0
此代碼編譯並運行。當客戶端連接時,WSAWaitForMultipleEvents返回nReturnCode = 0(相當於WSA_WAIT_EVENT_0)。但是代碼總是顯示「EVENT:NOT ACCEPT」,當我在調試模式下查看NetworkEvents時,它完全填充了零。WSAWaitForMultipleEvents成功返回,但WSANETWORKEVENTS對象爲空
我沒想到這段代碼能夠工作,因爲我不知道如何初始化變量NetworkEvents。我不必以某種方式將它「綁定」到套接字上嗎?結構應該如何知道它應該存儲ListenSocket的網絡事件?
WSAEVENT event = WSACreateEvent();
WSAEventSelect(ListenSocket, event, FD_CONNECT | FD_ACCEPT | FD_READ | FD_WRITE | FD_CLOSE);
//DWORD cEvents = MAKELONG(MAKEWORD(0, 0), MAKEWORD(0, 1));
WSAEVENT lphEvents[1] = {event};
//lphEvents[0] = event;
//DWORD dwTimeout = MAKELONG(MAKEWORD(0, 0), MAKEWORD(0, 0));
WSANETWORKEVENTS NetworkEvents = {0};
int nReturnCode = WSAWaitForMultipleEvents(1, &lphEvents[0], false, WSA_INFINITE, false);
if ((NetworkEvents.lNetworkEvents & FD_ACCEPT) == FD_ACCEPT) {
std::cout << "EVENT: ACCEPT !" << std::endl;
} else {
std::cout << "EVENT: NOT ACCEPT !" << std::endl;
}
這就是答案可能缺少
WSAEnumNetworkEvents
通話。謝謝 ! – EarnieWSANETWORKEVENTS :: lNetworkEvents可以包含多個事件嗎? – Quest