完成端口GetQueuedCompletionStatus()返回错误,怎样获得真正的错误代码

时间:2021-04-15 17:38:34

GetQueuedCompletionStatus()返回错误,说明I/O失败。此时调用GetLastError()得到的往往是ERROR_NETNAME_DELETED(64),WSAGetLastError()也一样,这显然不是真正的错误代码,那么怎么得到真正的错误代码呢?

给出下面的代码:

int YourIOCPClass::GetSockError(WSAOVERLAPPED* pWSAOVERLAPPED)
{
DWORD dwTrans;
DWORD dwFlags;
if(FALSE == WSAGetOverlappedResult(m_IOSock, pWSAOVERLAPPED, &dwTrans, FALSE, &dwFlags))
return WSAGetLastError();
else
return ERROR_SUCCESS;
}

使用了WSAGetOverlappedResult()函数,封装一下就可以用在代码里了:)