完成端口(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文档下载到电脑

精彩图片

热门精选

大家正在看

× 游客快捷下载通道(下载后可以自由复制和排版)

限时特价:7 元/份 原价:20元

支付方式:

开通VIP包月会员 特价:29元/月

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:fanwen365 QQ:370150219