我试图通过WSAWaitForMulipleObjects获取FD_CLOSE事件(C++)。在WSASelectEvent中,我只设置了FD_CLOSE。但是,等待返回和网络激活也返回0,但NetworkEvents从激活状态返回0,所以我无法在其中看到FD_CLOSE。WSAWaitForMultipleEvents和NetworkEvents
任何帮助?
谢谢。
void EventThread(void* obj)
{
WSANETWORKEVENTS NetworkEvents;
WSAEVENT EventArray[WSA_MAXIMUM_WAIT_EVENTS];
DWORD EventTotal = 0;
EventArray[EventTotal] = WSACreateEvent();
EventTotal++;
int res;
int index;
if(WSAEventSelect(_socket, EventArray[EventTotal - 1], FD_CLOSE)==SOCKET_ERROR)
Logger::GetInstance() << "WSAEventSelect failed with error " << WSAGetLastError() << endl;
bool bResult;
while(true)
{
if((index = WSAWaitForMultipleEvents(EventTotal, EventArray, FALSE, WSA_INFINITE, FALSE))==WSA_WAIT_FAILED)
{
Logger::GetInstance() << "WSAWaitForMultipleEvents failed with error " << WSAGetLastError() << endl;
}
if ((index != WSA_WAIT_FAILED) && (index != WSA_WAIT_TIMEOUT)) {
res = WSAEnumNetworkEvents(_socket, EventArray[index - WSA_WAIT_EVENT_0], &NetworkEvents) ;
if(NetworkEvents.lNetworkEvents & FD_CLOSE)
{
if(NetworkEvents.iErrorCode[FD_CLOSE_BIT] !=0)
{
Logger::GetInstance() << "FD_CLOSE failed with error " << NetworkEvents.iErrorCode[FD_CLOSE_BIT] << endl;
}
else
{
Logger::GetInstance() << "FD_CLOSE is OK!!! " << NetworkEvents.iErrorCode[FD_CLOSE_BIT] << endl;
}
}
}
}
}
你做了什么来触发事件? (尽可能精确。) – 2011-12-18 09:53:10
通过WSAEventSelect注册到FD_CLOSE,然后WSAWaitForMultipleEvents – gln 2011-12-18 09:57:57
正确,但是您是如何触发事件的?这就是你等待事件的方式,但你是如何使事件发生的? – 2011-12-18 09:58:28