ServerSocket.h
资源名称:1731.rar [点击查看]
上传用户:swkcbjrc
上传日期:2016-04-02
资源大小:45277k
文件大小:1k
源码类别:
游戏
开发平台:
Visual C++
- #pragma once
- #include <WinSock2.h>
- #pragma comment (lib,"ws2_32.lib")
- typedef unsigned (WINAPI *PBEGINTHREADEX_THREADFUNC)( LPVOID lpThreadParameter);
- typedef unsigned *PBEGINTHREADEX_THREADID;
- #define LOGMESSAGE(x) printf(x)
- class CServerSocket
- {
- friend UINT ServerListenThread(LPVOID lParam);
- friend UINT OverlappedThread(LPVOID lParam);
- public:
- CServerSocket(void);
- ~CServerSocket(void);
- bool StartupAcceptThread();
- int StartListening(const UINT&);
- bool StartupWorkThread();
- int StopListening();
- private:
- UINT m_nPort;
- int InitWSASocket();
- int GetEmptySocket();
- HANDLE m_hAcceptThread;
- HANDLE m_hWorkThread;
- public:
- SOCKET sockListen;
- SOCKET sockAcceptArray[WSA_MAXIMUM_WAIT_EVENTS]; // 与客户端通信的SOCKET
- WSAEVENT EventArray[WSA_MAXIMUM_WAIT_EVENTS]; // 与重叠结构配套的事件组
- WSAOVERLAPPED AcceptOverlapped[WSA_MAXIMUM_WAIT_EVENTS]; // 重叠结构,每个SOCKET操作对应一个
- WSABUF DataBuf[WSA_MAXIMUM_WAIT_EVENTS]; // 接收缓冲区,WSARecv的参数,每个SCOKET对应一个
- DWORD dwEventTotal,dwRecvBytes,Flags;
- int nSockIndex; // socket数组的编号
- BOOL bOverlapped; // 是否处理重叠请求
- };