Did you report errors and terminate the thread when a function call fails?
There is at least one wrong call that should result in an error return (best case) or undefined behaviour (worst case):
WSAWaitForMultipleEvents(2, &hEvent, FALSE, WSA_INFINITE, FALSE);
You are passing
2
for the number of events and the address of a single
hEvent
.
So it must be one of these:
WSAWaitForMultipleEvents(1, &hEvent, FALSE, WSA_INFINITE, FALSE);
WSAEVENT hEvents[2];
hEvents[0] = hEvent;
hEvents[1] = hOtherEvent;
WSAWaitForMultipleEvents(2, hEvents, FALSE, WSA_INFINITE, FALSE);