libmoost
|
Note, SIGKILL and SIGSTOP are not handled (this is a Posix restriction). More...
#include <quit_handler.hpp>
Public Types | |
typedef boost::function< void()> | handler_t |
Static Public Member Functions | |
static void | set (handler_t const &handler, bool trap_abort=true, bool trap_hup=false) |
Private Member Functions | |
void | register_handler (bool trap_abort) |
Static Private Member Functions | |
static quit_handler & | get_single_instance () |
static void | sighandler (int) |
Private Attributes | |
handler_t | handler_ |
struct sigaction | sa_ |
Note, SIGKILL and SIGSTOP are not handled (this is a Posix restriction).
This class represent and very simple way to trap and handle termination signals. It is not and never was intended to be a fully fledged signal handling framework. It's only job in life is to allow you to register a handler (which can be a simple free standing function or a functor), which will be called if any of the standard (and trapable) signals are raised. The idea is that you use your custom handler to shutdown your process gracefully; allowing you to persist data and stop services.
To use it just call it from an approppriate place in your main thread before you start any services or actions that might need clearing up on termination. It is up to you to ensure your custom handler shuts down your process. The normal action of termination will be disabled.
By default SIGABRT is also handled but you can disable this as required.
By default SIGHUP is not handled. You can add this if required but the preferred method is to use the "hup_handler" and reload the config.
Definition at line 60 of file quit_handler.hpp.
typedef boost::function<void ()> moost::process::quit_handler::handler_t |
Definition at line 71 of file quit_handler.hpp.
static quit_handler& moost::process::quit_handler::get_single_instance | ( | ) | [inline, static, private] |
void moost::process::quit_handler::register_handler | ( | bool | trap_abort | ) | [inline, private] |
Definition at line 103 of file quit_handler.hpp.
static void moost::process::quit_handler::set | ( | handler_t const & | handler, |
bool | trap_abort = true , |
||
bool | trap_hup = false |
||
) | [inline, static] |
Definition at line 74 of file quit_handler.hpp.
static void moost::process::quit_handler::sighandler | ( | int | ) | [inline, static, private] |
Definition at line 91 of file quit_handler.hpp.
Definition at line 88 of file quit_handler.hpp.
struct sigaction moost::process::quit_handler::sa_ [private] |
Definition at line 102 of file quit_handler.hpp.