手机版

完成端口(IOCP)的实现(4)

发布时间:2021-06-06   来源:未知    
字号:

整理的一个简单的完成端口类

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

完成端口(IOCP)的实现(4).doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
×
二维码
× 游客快捷下载通道(下载后可以自由复制和排版)
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能出现无法下载或内容有问题,请联系客服协助您处理。
× 常见问题(客服时间:周一到周五 9:30-18:00)