views:

33

answers:

1

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.

+2  A: 

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.

Len Holgate
Thanks =) Nice code too. Much cleaner looking and understandable than most of the projects that I have seen.
Nick
The original idea was to make it easy to reuse the code in various projects that I had at the time. All of the example code I'd seen was very hard to reuse and often included what I viewed as 'dubious' designs... Now, 10 years later, I'm still using code that's based on that original code and still building clients and servers quickly :) So it all worked out nicely.
Len Holgate