I have a Winsock based server application which uses Windows Winsock I/O Completion Ports.
As such, each connection accepted is associated with the listening socket to start receiving notifications (read, write, close etc').
The listening socket has a backlog of 100 pending connections.
All is good.
At some point I want to stop accepting new connections yet keep communication with already connected existing connected sockets.
I figured I could do one of:
- Stop calling WSAAccept().
- Set the backlog to zero, effectively disallowing any connection to pend.
- Call shutdown() & closesocket() on the listening socket.
Now, option #1 gives the expected results; My application doesn't process new connections, BUT it does accept up to the backlog's amount (100). Connections are practically made - I don't want it!
Option #2; Can I do that? How? Couldn't find on MSDN nor google. The documentation of listen() at MSDN says;
If the listen function is called on an already listening socket, it will return success without changing the value for the backlog parameter. Setting the backlog parameter to 0 in a subsequent call to listen on a listening socket is not considered a proper reset, especially if there are connections on the socket.
Not good for me.
If I could do so in a safe way I would combine it with option #1, effectively really stopping establishing any new connections on the machine (through the listening port!).
Option #3 actually works; After closing the listening socket I can still communicate with existing connections, and the backlog is gone (well, closed the listening socket!).
My concern is that this approach might have some side-effects. Can anyone confirm?