整理的一个简单的完成端口类
UE)
{
if(count++ >= 5)
{
TerminateThread(m_hThread,0);
break;
}
GetExitCodeThread(m_hThread,&code);
if(code == STILL_ACTIVE)
{
Sleep(1000);
continue;
}
else
break;
}
CloseHandle(m_hThread);
m_hThread = NULL;
}
}
void WorkThread::SendMessage(UINT Msg, WPARAM wParam, LPARAM lParam)
{
if (m_hThread)
PostThreadMessage(m_nThreadID, Msg, wParam, lParam);
}
void WorkThread::SetPriority(int priority)
{
if (m_hThread)
SetThreadPriority(m_hThread, priority);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////NetClient
NetClient::NetClient()
{
m_socket = NULL;
m_pComKey = NULL;
}
NetClient::NetClient(int socket)
{
m_socket = socket;
}
NetClient::~NetClient()
{
if(m_socket)
closesocket(m_socket);
}
void NetClient::SendPacket(void* pData,bool encrypt)
{
g_pHostServer->SendPacket(m_socket,pData,encrypt);
}
void NetClient::Disconnect()
{
if(m_socket)
{
closesocket(m_socket);
m_socket = NULL;
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////NetCompletionPort
NetCompletionPort::NetCompletionPort()
{
g_pHostServer = this;
m_pAcceptEx = NULL;
m_comPort = NULL;
m_port = 0;
m_listenSocket = NULL;
m_hEventListen = NULL;
m_isCreate = FALSE;
m_pWorkThreadList = new std::vector<WorkThread*>; //工作线程数组 注意:这个对象似乎没有释放
m_pThreadAccept = NULL;
m_pClientList = new std::map<int,NetClient*>; //客户端集合
m_pConnectList = new std::set<LPPER_IO_CONTEXT>; //连接请求IO集合
m_pIoMemList = new std::deque<LPPER_IO_CONTEXT>; //IO内存队列
m_pHandleMemList = new std::deque<LPPER_HANDLE_CONTEXT>; //句柄内存队列
m_pClientList->clear();
m_pConnectList->clear();
m_pIoMemList->clear();
m_pHandleMemList->clear();
InitializeCriticalSection(&m_clientListSection);
InitializeCriticalSection(&m_conSection);
InitializeCriticalSection(&m_ioMenListSection);
InitializeCriticalSection(&m_hdMemListSection);
}
NetCompletionPort::~NetCompletionPort()
{
// NetCompletionPort::StopServer();
delet
e m_pClientList;
delete m_pConnectList;
delete m_pIoMemList;
delete m_pHandleMemList;
DeleteCriticalSection(&m_clientListSecti