I'm using IOCP on Windows. Previously I used method GetQueuedCompletionStatus
to poll the queue and everything was fine. But when I decided to refactor the logic in the way to utilize completion routine with WSARecv
call it always fails with the error WSAEINVAL
(10022). This code is in thread created with CreateTread
int flags = 0;
m_iocport = CreateIoCompletionPort(INVALID_HANDLE_VALUE, NULL, NULL, 0);
handle = CreateIoCompletionPort(clientSocket, m_iocport, 0, 0);
OVERLAPPED_EX *over = new OVERLAPPED_EX();
result = WSARecv(clientSocket, &over->m_wsabuf, 1, NULL, &flags, over, WorkerRoutine);
And the worker routine is empty and has following definition:
void static CALLBACK WorkerRoutine(DWORD Error, DWORD BytesTransferred, LPWSAOVERLAPPED Overlapped, DWORD InFlags) {}
When I pass NULL
instead of WorkerRoutine
to the WSARecv method everything works fine. But when I pass completion routine to the call it fails with the error 10022. I tried to use WorkerRoutine
and &WorkerRoutine
nothing helps.
the hEvent
property is set to NULL in the OVERLAPPED_EX object.