dfx 0.1.0
Linux-based dynamic dataflow executor
Loading...
Searching...
No Matches
dfx::FdWatch::SignalFdWatcher Class Reference

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)

Detailed Description

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.

Note
For signals to be routed to signalfd, they must be blocked in the thread(s) that should not handle them via traditional signal handlers. This class does the signal masking in its constructor.

Member Typedef Documentation

◆ Callback

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.

Member Enumeration Documentation

◆ SigChldMode

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).

Constructor & Destructor Documentation

◆ SignalFdWatcher()

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.

Parameters
pollerPoller used to monitor the signalfd.
signalsList of signals to route to signalfd (e.g. {SIGINT, SIGTERM}).
cbCallback invoked when a watched signal is received.
sigChldModesOptional SIGCHLD behavior flags (only relevant if SIGCHLD is in signals).
Precondition
cb must be valid.
Note
This class is non-copyable and non-movable

The documentation for this class was generated from the following file: