I'm triying to implement a server which uses IOCompletionPort to read from its clients. I have something very similar to this example.
If I understand correctly, this should be my design:
After some reading on WSARecv (Here) I discovered that WSARecv might return immediately with the data if the data is ready. That seems kinda weird because that means that a worker could loop on WSARecv without returning to the IO queue if the client sends fast enough - And that could cause client starvation...
Hereby my questions are:
This is how I use WSARecv:
flags = 0;
receiveResult = WSARecv(clientSocket, &(olStruct->Buffer), 1, &bytesReceived, &flags, (OVERLAPPED*)olStruct, NULL);
olStruct is an extension for the OVERLAPPED struct.
EDIT:
I ended up reposting what I got from WSARecv using PostQueuedCompletionStatus. I'd love to hear other solutions though
See Answer
It seems that when WSARecv completes immediately it returns the buffer AND posts to the IOCompletionPort queue.
So the current design still stands.