Question

I can find tonnes of article's about starting up an IOCP server, but none about properly shutting it down =/

What is the proper way to shut the server down when you are done? more specifically, I already use PostQueuedCompletionStatus() to tell the worker threads to quit, but don't I also need to cancel all the pending IO, and close all the sockets before I quit?

I found CancelSynchronousIo() on MSDN, and it seems like I could have each worker thread call this function when it receives the completion notification to quit...is this the proper way to do it?

thanks for any help on this.

Was it helpful?

Solution

If you loop through all of the open connections and shut down all of the sockets then all of the pending I/O will complete on its own and the server will shut down. You can either close with a lingering close to allow any pending write data to complete or you can turn linger off on the sockets and cause pending write data to be discarded and the connections to be reset with an RST rather than shutdown cleanly.

I have some IOCP server examples here, which you may already have seen, but which show how you could achieve a clean shutdown.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top