将所需要经常引用的头文件并在一个head.h中:
#ifndef __HEAD_H__
#define __HEAD_H__
#ifdef WIN32
#include <winsock2.h>
#include<time.h>
#else
#include<stdlib.h>
#include <sys/types.h>
#include <sys/sysinfo.h>
#include <sys/socket.h>
#include <sys/time.h>
#include <sys/ioctl.h>
#include <pthread.h>
#include <arpa/inet.h>
#include<netdb.h>
#include <error.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/signal.h>
#include <string.h>
#include <stdarg.h>
#include <sys/epoll.h>
#endif
#include <stdio.h>
#include "config.h"
#include "ThreadCpp.h"
#include "MsgQueue.h"
#include "SocketOps.h"
#ifdef WIN32
#pragma comment(lib,"Ws2_32")
#endif
#endif
监听的套接字:
#ifndef _LISTENSOCKET_H
#define _LISTENSOCKET_H
#include "head.h"
class CListenSocket
{
public:
CListenSocket(const char * ListenAddress, DWORD Port);
~CListenSocket();
SOCKET GetSocket(){return m_socket;};
private:
SOCKET m_socket;
struct sockaddr_in m_address;
};
#endif