|
CppZmqZoltanExt 0.0.1
|
Signal interrupt handling for graceful application shutdown. More...
#include <atomic>#include "cppzmqzoltanext/czze_export.h"

Go to the source code of this file.
Functions | |
| CZZE_EXPORT void | zmqzext::install_interrupt_handler () noexcept |
| Install signal handlers for SIGINT and SIGTERM. | |
| CZZE_EXPORT void | zmqzext::restore_interrupt_handler () noexcept |
| Restore the previously stored signal handlers. | |
| CZZE_EXPORT bool | zmqzext::is_interrupted () noexcept |
| Check if a program interrupt was received. | |
| CZZE_EXPORT void | zmqzext::reset_interrupted () noexcept |
| Reset the interrupt flag to false. | |
Signal interrupt handling for graceful application shutdown.
This header provides signal handling utilities for managing SIGINT (Ctrl+C) and SIGTERM signals. It establishes a mechanism for detecting and responding to interrupt signals, enabling graceful shutdown of applications.
The module manages signal handlers through a pair of installation and restoration functions, allowing applications to safely install the signal handler provided by this module and restore previous handlers when needed.
The signal handler provided by this module sets an atomic flag that tracks the interrupt state, which can be checked by the application to determine when shutdown should be initiated.
The atomic flag is monitored by the poller_t and loop_t classes to allow them to detect interrupt conditions and return early from polling or loop operations.
Typically, an application will call install_interrupt_handler() during application initialization and perform a clean shutdown when its main poller_t or loop_t instance indicates that an interrupt has occurred.
Key features:
Distributed under the MIT License (MIT) (See accompanying file LICENSE or copy at http://opensource.org/licenses/MIT)
Definition in file interrupt.h.
|
noexcept |
Install signal handlers for SIGINT and SIGTERM.
Installs a signal handler for SIGINT (Ctrl+C) and SIGTERM signals. When either signal is received, a global atomic flag is set to true, indicating that an interrupt has been requested. Other parts of the application can check this flag via is_interrupted() to implement graceful shutdown logic.
The function preserves the current signal handlers before installing new ones on the first call or after a call to restore_interrupt_handler(). This allows these original handlers to be restored later via restore_interrupt_handler().
Definition at line 82 of file interrupt.cpp.
|
noexcept |
Check if a program interrupt was received.
Checks whether a SIGINT (Ctrl+C) or SIGTERM signals have been received since the interrupt handlers were installed or since the last call to reset_interrupted().
Definition at line 118 of file interrupt.cpp.
|
noexcept |
Reset the interrupt flag to false.
Resets the atomic interrupt flag to false, allowing the application to continue monitoring for new interrupt signals. This function is useful when you want to handle an interrupt and then continue execution while maintaining the ability to detect future interrupts.
Definition at line 120 of file interrupt.cpp.
|
noexcept |
Restore the previously stored signal handlers.
Restores the signal handlers that were active before the first call to install_interrupt_handler(). This function does nothing if install_interrupt_handler() was never called or if the handlers were already restored.
After calling this function, a subsequent call to install_interrupt_handler() will save the current handlers (which are now the original handlers) before installing new custom signal handlers.
Definition at line 90 of file interrupt.cpp.