I have written a test TCP server using IOCP. The server just listens on a port and dumps on the screen the received data (it sends nothing back to the client).
The problem I am facing is that, if the server receives a second connection while there is one connection open, the second connection is not accepted until the first one is closed.
The program works as follows:
Create an I/O completion port (CreateIoCompletionPort(INVALID_HANDLE_VALUE, 0, 0, 0)).
Create listener socket.
Bind listener socket.
Associate listener socket with the I/O completion port.
Create 4 sockets (maximum number of simultaneous connections) (4 x WSASocket(AF_INET, SOCK_STREAM, IPPROTO_TCP, nullptr, 0, WSA_FLAG_OVERLAPPED)).
Associate the 4 sockets with the I/O completion port.
Start an asynchronous accept for each socket (4 x AcceptEx()).
Create two threads which loop calling GetQueuedCompletionStatus().
When a connection is accepted, I call setsockopt() with the option SO_UPDATE_ACCEPT_CONTEXT and start an asynchronous read (WSARecv()).
After data has been received, I start another asynchronous read (WSARecv()).
When the client closes the connection, I call DisconnectEx() and, once DisconnectEx() has completed, I call AcceptEx() again.
Why don't I get notified in GetQueuedCompletionStatus() when a second connection is received?
The output of the program and the source code can be found here: