Getting and processing system signals as tasks
When writing some server application (especially for Linux OS), catching and processing the 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.
Getting ready
We will need code from the first recipe of this chapter. A sound knowledge of Boost.Function
is also required.
This recipe requires linking with the boost_system
and boost_thread
libraries.
How to do it...
This recipe is similar to the recipes from 2 to 4 of this chapter: we have async
signal waiting functions, some async
signal handlers, and some support code.
- Let's start by 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:
protected: static boost::asio::signal_set& signals() { ...