Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

List active handlers in boost io_service

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.

like image 485
Gearoid Murphy Avatar asked Nov 14 '22 07:11

Gearoid Murphy


1 Answers

There are a few issues:

  • The book-keeping will become expensive, especially in systems with large numbers of operations and significant concurrency.
  • Even if you did get a list, you don't know whether it is up-to-date.

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.

like image 114
janm Avatar answered Dec 16 '22 23:12

janm