首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 其他教程 > 开源软件 >

移栽了开源远程控制Gh0st3.6中的IOCP完成端口到dll

2012-12-25 
移植了开源远程控制Gh0st3.6中的IOCP完成端口到dllGhost3.6 是性能很好的一款开源远程控制。其IOCP模型算是

移植了开源远程控制Gh0st3.6中的IOCP完成端口到dll

Ghost3.6 是性能很好的一款开源远程控制。其IOCP模型算是比较好的了。我将其中的IOCP完成端口模型抠出来封装成了DLL。。只是没有进行网络测试。


源代码:http://download.csdn.net/detail/witch_soya/4882068


服务器端初始化函数

/************************************************************************//* 函数类型:线程函数函数功能:工作者线程*//************************************************************************/DWORD WINAPI NetEngineServer::ThreadFunc( LPVOID lPvoid ){ULONG ulFlags = MSG_PARTIAL;NetEngineServer* pThis = reinterpret_cast<NetEngineServer*>(lPvoid);HANDLE hCompletionPort = pThis->m_hCompletionPort;DWORDdwIoSize;LPOVERLAPPEDlpOverlapped;ClientContext*lpClientContext;OVERLAPPEDPLUS*pOverlapPlus;BOOLbError;BOOLbEnterRead;InterlockedIncrement(&pThis->m_nCurrentThreads);InterlockedIncrement(&pThis->m_nBusyThreads);for (BOOL bStayInPool = TRUE; bStayInPool && pThis->m_bTimeToKill == false; ) {pOverlapPlus= NULL;lpClientContext = NULL;bError= false;bEnterRead= false;// Thread is Block waiting for IO completionInterlockedDecrement(&pThis->m_nBusyThreads);// Get a completed IO request.  调用成功返回非零BOOL bIORet = GetQueuedCompletionStatus(hCompletionPort,&dwIoSize,(LPDWORD) &lpClientContext,&lpOverlapped, INFINITE);DWORD dwIOError = GetLastError();pOverlapPlus = CONTAINING_RECORD(lpOverlapped, OVERLAPPEDPLUS, m_ol);int nBusyThreads = InterlockedIncrement(&pThis->m_nBusyThreads);if (!bIORet && dwIOError != WAIT_TIMEOUT )  //调用GetQueuedCompletionStatus不成功返回0  而失败原因不是超时{if (lpClientContext && pThis->m_bTimeToKill == false){pThis->RemoveStaleClient(lpClientContext, FALSE);}continue;// anyway, this was an error and we should exitbError = true;}if (!bError)//过程中没有发生错误{// Allocate another thread to the thread Pool?if (nBusyThreads == pThis->m_nCurrentThreads){if (nBusyThreads < pThis->m_nThreadPoolMax){if (pThis->m_cpu.GetUsage() > pThis->m_nCPUHiThreshold){UINT nThreadID = -1;}}}// Thread timed out - IDLE?if (!bIORet && dwIOError == WAIT_TIMEOUT) {if (lpClientContext == NULL){if (pThis->m_cpu.GetUsage() < pThis->m_nCPULoThreshold){// Thread has no outstanding IO - Server hasn't much to do so dieif (pThis->m_nCurrentThreads > pThis->m_nThreadPoolMin)bStayInPool =  FALSE;}bError = true;}}}//这里开始处理接收到的数据if (!bError){if(bIORet && NULL != pOverlapPlus && NULL != lpClientContext) {try{pThis->ProcessIOMessage(pOverlapPlus->m_ioType, lpClientContext, dwIoSize);}catch (...) {}}}if(pOverlapPlus)delete pOverlapPlus; // from previous call}InterlockedDecrement(&pThis->m_nWorkerCnt);InterlockedDecrement(&pThis->m_nCurrentThreads);InterlockedDecrement(&pThis->m_nBusyThreads);return 0;}



热点排行