Reputation: 12116
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.
Upvotes: 5
Views: 349
Reputation: 18339
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.
Upvotes: 1