18,363
社区成员




BOOL bIORet = GetQueuedCompletionStatus(
hCompletionPort,
&dwIoSize,
(LPDWORD) &lpClientContext,
&lpOverlapped, INFINITE);
// Simulate workload (for debugging, to find possible reordering)
//Sleep(20);
// If Something whent wrong..
if (!bIORet)
{
DWORD dwIOError = GetLastError();
if(dwIOError != WAIT_TIMEOUT) // It was not an Time out event we wait for ever (INFINITE)
{
TRACE(_T("GetQueuedCompletionStatus errorCode: %i, %s\n"),WSAGetLastError(),pThis->ErrorCode2Text(dwIOError));
// if we have a pointer & This is not an shut down..
//if (lpClientContext!=NULL && pThis->m_bShutDown == false)
if (lpClientContext!=NULL)
{
/*
* ERROR_NETNAME_DELETED Happens when the communication socket
* is cancelled and you have pendling WSASend/WSARead that are not finished.
* Then the Pendling I/O (WSASend/WSARead etc..) is cancelled and we return with
* ERROR_NETNAME_DELETED..
*/
if(dwIOError==ERROR_NETNAME_DELETED)
{
//TRACE("ERROR_NETNAME_DELETED\r\n");
pThis->DisconnectClient(lpClientContext);
TRACE(">IOWORKER1 (%x)\r\n",lpClientContext);
pThis->ReleaseClientContext(lpClientContext); //Later Implementati
}else
{ // Should not get here if we do: disconnect the client and cleanup & report.
pThis->AppendLog(pThis->ErrorCode2Text(dwIOError));
pThis->DisconnectClient(lpClientContext);
TRACE(">IOWORKER2 (%x)\r\n",lpClientContext);
pThis->ReleaseClientContext(lpClientContext); //Should we do this ?
}
// Clear the buffer if returned.
pOverlapBuff=NULL;
if(lpOverlapped!=NULL)
pOverlapBuff=CONTAINING_RECORD(lpOverlapped, CIOCPBuffer, m_ol);
if(pOverlapBuff!=NULL)
pThis->ReleaseBuffer(pOverlapBuff);
continue;
}
// We shall never come here
// anyway this was an error and we should exit the worker thread
bError = true;
pThis->AppendLog(pThis->ErrorCode2Text(dwIOError));
pThis->AppendLog("IOWORKER KILLED BECAUSE OF ERROR IN GetQueuedCompletionStatus");
pOverlapBuff=NULL;
if(lpOverlapped!=NULL)
pOverlapBuff=CONTAINING_RECORD(lpOverlapped, CIOCPBuffer, m_ol);
if(pOverlapBuff!=NULL)
pThis->ReleaseBuffer(pOverlapBuff);
continue;
}
}