When writing some server applications (especially for Linux OS), catching and processing signals is required. Usually, all the signal handlers are set up at server start and do not change during the application's execution.
The goal of this recipe is to make our tasks_processor
class capable of processing signals.
We will need code from the first recipe of this chapter. Good knowledge of Boost.Bind
and Boost.Function
is also required.
This recipe is similar to previous ones; we have some signal handlers, functions to register them, and some support code.
Let's start with including the following headers:
#include <boost/asio/signal_set.hpp> #include <boost/function.hpp>
Now we add a member for signals processing to the
tasks_processor
class:private: boost::asio::signal_set signals_; boost::function<void(int)> users_signal_handler_;
The function that will be called upon signal capture is as follows...