![]() |
dfx 0.1.0
Linux-based dynamic dataflow executor
|
Watches POSIX signals via signalfd and dispatches them through a callback. More...
#include <dfx-fdwatch/SignalFdWatcher.hpp>
Public Types | |
| enum class | SigChldMode { Default = 0x01 , NoChldStop = 0x02 , NoChldWait = 0x04 } |
| Additional behavior configuration for SIGCHLD. More... | |
| using | Callback = std::move_only_function<void (signalfd_siginfo const &)> |
| Callback invoked for each received signal. The callback receives the signalfd_siginfo payload read from the FD. | |
Public Member Functions | |
| DECLARE_FLAGS (SigChldModes, SigChldMode) | |
| SignalFdWatcher (Poller &poller, std::initializer_list< int > signals, Callback cb, SigChldModes sigChldModes=SigChldMode::Default) | |
| Constructs a watcher and registers the internal signalfd into the poller. | |
| DISABLE_COPY_AND_MOVE (SignalFdWatcher) | |
Watches POSIX signals via signalfd and dispatches them through a callback.
SignalFdWatcher creates a signalfd that receives the specified signals and registers it to a Poller. When a signal is delivered, the watcher reads the pending signalfd_siginfo and invokes the user callback.
This approach makes signal handling event-loop friendly (no async-signal-safe restrictions in the callback) and integrates naturally with epoll/poll based loops.
The watcher owns the underlying FD through PollerFd and deregistration/cleanup happens as part of its lifetime management.
| using dfx::FdWatch::SignalFdWatcher::Callback = std::move_only_function<void (signalfd_siginfo const &)> |
Callback invoked for each received signal. The callback receives the signalfd_siginfo payload read from the FD.
|
strong |
Additional behavior configuration for SIGCHLD.
These options are only meaningful when watching SIGCHLD. They typically correspond to sigaction() flags such as SA_NOCLDSTOP and SA_NOCLDWAIT.
| Enumerator | |
|---|---|
| Default | Default SIGCHLD behavior. |
| NoChldStop | Do not generate SIGCHLD when children stop/continue (SA_NOCLDSTOP). |
| NoChldWait | Request that child exit does not leave zombies (SA_NOCLDWAIT). |
| dfx::FdWatch::SignalFdWatcher::SignalFdWatcher | ( | Poller & | poller, |
| std::initializer_list< int > | signals, | ||
| Callback | cb, | ||
| SigChldModes | sigChldModes = SigChldMode::Default ) |
Constructs a watcher and registers the internal signalfd into the poller.
| poller | Poller used to monitor the signalfd. |
| signals | List of signals to route to signalfd (e.g. {SIGINT, SIGTERM}). |
| cb | Callback invoked when a watched signal is received. |
| sigChldModes | Optional SIGCHLD behavior flags (only relevant if SIGCHLD is in signals). |
cb must be valid.