I am writing a socket client-type application with boost::asio. I am doing something like the example wherein they use an asio::signal_set
to catch signals, and in the signal handler they call io_service::stop
to stop the client gracefully and quit the program.
However, io_service::run
returns when there is no more work to do (or stop
is called) and unfortunately, the signal_set
counts as work. So, even when my client is out of work, it is still waiting on a signal to call the signal handler and the program can only end when you hit Ctrl-C or whatever. I would like it to exit when either a signal is received or the sockets quit giving work to the io_service
, i.e. a normal exit.
Is there a way that I can get the io_service
to keep running only as long as there is work other than the signal handler? (I cannot call stop
myself because I can't know when there's no more work; only the io_service
knows.)