DataStorm
0.1
Data Distribution Service
|
Provides a portable way to handle Ctrl-C and Ctrl-C like signals. More...
#include <DataStorm/DataStorm.h>
Public Member Functions | |
CtrlCHandler (CtrlCHandlerCallback cb=nullptr) | |
Register a function that handles Ctrl-C like signals. More... | |
~CtrlCHandler () | |
Unregister the callback function. More... | |
CtrlCHandlerCallback | setCallback (CtrlCHandlerCallback cb) noexcept |
Replace the signal callback. More... | |
CtrlCHandlerCallback | getCallback () const noexcept |
Obtain the signal callback. More... | |
Static Public Member Functions | |
static void | maskSignals () noexcept |
Linux and macOS: mask the SIGHUP, SIGINT and SIGTERM signals. More... | |
Provides a portable way to handle Ctrl-C and Ctrl-C like signals.
On Linux and macOS, the CtrlCHandler handles SIGHUP, SIGINT and SIGTERM. On Windows, it is essentially a wrapper for SetConsoleCtrlHandler().
|
explicit |
Register a function that handles Ctrl-C like signals.
This constructor first calls maskSignals if it was not already called. On Linux and macOS, it creates a thread that waits on SIGHUP, SIGINT and SIGTERM using sigwait. Only a single CtrlCHandler object can exist in a process at a give time.
cb | The callback function to invoke when a signal is received. |
DataStorm::CtrlCHandler::~CtrlCHandler | ( | ) |
Unregister the callback function.
This destructor does not "unmask" SIGHUP, SIGINT and SIGTERM or unregister the handler routine on Windows. As a result, Ctrl-C and similar signals are just ignored after this destructor completes.
|
noexcept |
Obtain the signal callback.
|
staticnoexcept |
Linux and macOS: mask the SIGHUP, SIGINT and SIGTERM signals.
It is essential to call maskSignals before creating any thread. Threads created later on will inherit this signal mask. Windows: call SetConsoleCtrlCHandler to register a handler routine that ignores signals.
|
noexcept |
Replace the signal callback.
cb | The new callback. |