Whilst building unit tests for a client/server system at work, I ran into a problem where my io_service was not releasing after I had shutdown all the active handlers (that I was aware of).
After a day of trawling through code, I came across the errant handler which had not been integrated into my client shutdown procedures.
My question is this: Is there an easy way to list the currently active handlers in the boost io_service?, if not, why not?
Any insight would be appreciated.
There are a few issues:
I don't know if these are the specific reasons for boost::asio, but these reasons jump out at me.
To solve the actual problem, destructors and scopes are your friend. I find it useful to have a container of handles to high level objects (eg. socket listeners) and just let these go out of scope when you want to shut down. I find shared_ptr is good, but you could use all kinds of variants.
If you have to call a stop()
method on every object you want to stop, you're going to forget something. Let destructors do the work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With