开发工具:
文件大小: 58kb
下载次数: 0
上传时间: 2014-06-05
详细说明:
#include #include #pragma comment(lib,"ws2_32.lib") #include "Buffer.h" #include "CpuUsage.h" #include #include //////////////////////////////////////////////////////////////////// #define NC_CLIENT_CONNECT 0x0001 #define NC_CLIENT_DISCONNECT 0x0002 #define NC_TRANSMIT 0x0003 #define NC_RECEIVE 0x0004 #define NC_RECEIVE_COMPLETE 0x0005 // 完整接收 class CLock { public: CLock(CRITICAL_SECTION& cs, const CString& amp; strFunc) { m_strFunc = strFunc; m_pcs = &cs; Lock(); } ~CLock() { Unlock(); } void Unlock() { LeaveCriticalSection(m_pcs); TRACE(_T("LC %d %s\n") , GetCurrentThreadId() , m_strFunc); } void Lock() { TRACE(_T("EC %d %s\n") , GetCurrentThreadId(), m_strFunc); EnterCriticalSection(m_pcs); } protected: CRITICAL_SECTION* m_pcs; CString m_strFunc; }; enum IOType { IOInitialize, IORead, IOWrite, IOIdle }; class OVERLAPPEDPLUS { public: OVERLAPPED m_ol; IOType m_ioType; OVERLAPPEDPLUS(IOType ioType) { ZeroMemory(this, sizeof(OVERLAPPEDPLUS)); m_ioType = ioType; } }; //lang2.1_3 struct ClientContext //简单分析ClientContext结构体然后回到 SendSelectCommand { SOCKET m_Socket; //套接字 // Store buffers CBuffer m_WriteBuffer; CBuffer m_CompressionBuffer; // 接收到的压缩的数据 CBuffer m_DeCompressionBuffer; // 解压后的数据 CBuffer m_ResendWriteBuffer; // 上次发送的数据包,接收失败时重发时用 int m_Dialog[2]; // 放对话框列表用,第一个int是类型,第二个是CDialog的地址 int m_nTransferProgress; // Input Elements for Winsock WSABUF m_wsaInBuffer; BYTE m_byInBuffer[8192]; // Output elements for Winsock WSABUF m_wsaOutBuffer; HANDLE m_hWriteComplete; // Message counts... purely for example purposes LONG m_nMsgIn; LONG m_nMsgOut; BOOL m_bIsMainSocket; // 是不是主socket ClientContext* m_pWriteContext; ClientContext* m_pReadContext; }; template<> inline UINT AFXAPI HashKey(CString & strGuid) { return HashKey( (LPCTSTR) strGuid); } #include "Mapper.h" typedef void (CALLBACK* NOTIFYPROC)(LPVOID, ClientContext*, UINT nCode); typedef CList ContextList; class CMainFrame; class CIOCPServer { public: void DisconnectAll(); CIOCPServer(); virtual ~CIOCPServer(); NOTIFYPROC m_pNotifyProc; CMainFrame* m_pFrame; bool Initialize(NOTIFYPROC pNotifyProc, CMainFrame* pFrame, int nMaxConnections, int nPort); static unsigned __stdcall ListenThreadProc(LPVOID lpVoid); static unsigned __stdcall ThreadPoolFunc(LPVOID WorkContext); static CRITICAL_SECTION m_cs; void Send(ClientContext* pContext, LPBYTE lpData, UINT nSize); void PostRecv(ClientContext* pContext); bool IsRunning(); void Shutdown(); void ResetConnection(ClientContext* pContext); LONG m_nCurrentThreads; LONG m_nBusyThreads; UINT m_nSendKbps; // 发送即时速度 UINT m_nRecvKbps; // 接受即时速度 UINT m_nMaxConnections; // 最大连接数 protected: void InitializeClientRead(ClientContext* pContext); BOOL AssociateSocketWithCompletionPort(SOCKET device, HANDLE hCompletionPort, DWORD dwCompletionKey); void RemoveStaleClient(ClientContext* pContext, BOOL bGraceful); void MoveToFreePool(ClientContext *pContext); ClientContext* AllocateContext(); LONG m_nWorkerCnt; bool m_bInit; bool m_bDisconnectAll; BYTE m_bPacketFlag[5]; void CloseCompletionPort(); void OnAccept(); bool InitializeIOCP(void); void Stop(); ContextList m_listContexts; ContextList m_listFreePool; WSAEVENT m_hEvent; SOCKET m_socListen; HANDLE m_hKillEvent; HANDLE m_hThread; HANDLE m_hCompletionPort; bool m_bTimeToKill; CCpuUsage m_cpu; LONG m_nKeepLiveTime; // 心跳超时 // Thread Pool Tunables LONG m_nThreadPoolMin; LONG m_nThreadPoolMax; LONG m_nCPULoThreshold; LONG m_nCPUHiThreshold; CString GetHostName(SOCKET socket); void CreateStream(ClientContext* pContext); BEGIN_IO_MSG_MAP() IO_MESSAGE_HANDLER(IORead, OnClientReading) IO_MESSAGE_HANDLER(IOWrite, OnClientWriting) IO_MESSAGE_HANDLER(IOInitialize, OnClientInitializing) END_IO_MSG_MAP() bool OnClientInitializing (ClientContext* pContext, DWORD dwSize = 0); bool OnClientReading (ClientContext* pContext, DWORD dwSize = 0); bool OnClientWriting (ClientContext* pContext, DWORD dwSize = 0); }; ...展开收缩
(系统自动生成,下载前可以参看下载内容)
下载文件列表
相关说明
- 本站资源为会员上传分享交流与学习,如有侵犯您的权益,请联系我们删除.
- 本站是交换下载平台,提供交流渠道,下载内容来自于网络,除下载问题外,其它问题请自行百度。
- 本站已设置防盗链,请勿用迅雷、QQ旋风等多线程下载软件下载资源,下载后用WinRAR最新版进行解压.
- 如果您发现内容无法下载,请稍后再次尝试;或者到消费记录里找到下载记录反馈给我们.
- 下载后发现下载的内容跟说明不相乎,请到消费记录里找到下载记录反馈给我们,经确认后退回积分.
- 如下载前有疑问,可以通过点击"提供者"的名字,查看对方的联系方式,联系对方咨询.