dfx 0.1.0
Linux-based dynamic dataflow executor
Loading...
Searching...
No Matches
SignalFdWatcher.hpp
1// SPDX-FileCopyrightText: 2025 Vincent Leroy
2// SPDX-License-Identifier: MIT
3//
4// This file is part of dfx.
5//
6// Licensed under the MIT License. See the LICENSE file in the project root
7// for full license information.
8
9#pragma once
10
11// Standard includes
12#include <initializer_list>
13#include <functional>
14#include <sys/signalfd.h>
15
16// Project includes
17#include "Events.hpp"
18#include "PollerFd.hpp"
22
23namespace dfx::FdWatch
24{
25class Poller;
26
46{
47public:
53 enum class SigChldMode
54 {
55 Default = 0x01,
56 NoChldStop = 0x02,
57 NoChldWait = 0x04,
58 };
59 DECLARE_FLAGS(SigChldModes, SigChldMode);
60
61public:
64 using Callback = std::move_only_function<void (signalfd_siginfo const &)>;
65
66public:
78 std::initializer_list<int> signals,
79 Callback cb,
80 SigChldModes sigChldModes = SigChldMode::Default);
82
83private:
84 void _onSignalFdTriggered(EventTriggers events);
85
86private:
87 Callback _cb;
88 PollerFd _signalFd;
89};
90} // !namespace dfx::FdWatch
91
93DECLARE_OPERATOR_FOR_FLAGS(dfx::FdWatch::SignalFdWatcher::SigChldModes)
94DECLARE_STD_FORMATTER_FOR_FLAGS(dfx::FdWatch::SignalFdWatcher::SigChldModes);
Convenience macros to explicitly control copy and move semantics.
#define DISABLE_COPY_AND_MOVE(ClassName)
Disable both copy and move.
Definition CopyMoveControl.hpp:37
Macro-based enum <-> string utilities for dfx.
#define DECLARE_ENUM_STRING_FUNCTIONS(E)
Declare the enum string API (and std::formatter) for enum type E.
Definition EnumString.hpp:327
Event interest and trigger flags for file-descriptor watching (Linux/epoll).
Typesafe enum bitmask wrapper and helper macros.
#define DECLARE_OPERATOR_FOR_FLAGS(FlagsName)
Declare a free operator| to combine two enum values into a Flags.
Definition Flags.hpp:291
#define DECLARE_STD_FORMATTER_FOR_FLAGS(FlagsName)
Declare a std::formatter<FlagsName> that prints set flags joined by |.
Definition Flags.hpp:308
#define DECLARE_FLAGS(FlagsName, Enum)
Declare a convenient alias for dfx::Utils::Flags<Enum>.
Definition Flags.hpp:275
Bitset wrapper for dfx::FdWatch::EventTrigger values.
RAII wrapper for the registration of a FD in a Poller.
Definition PollerFd.hpp:42
Abstract interface for FD-based event polling.
Definition Poller.hpp:37
std::move_only_function< void(signalfd_siginfo const &)> Callback
Callback invoked for each received signal. The callback receives the signalfd_siginfo payload read fr...
Definition SignalFdWatcher.hpp:64
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.
SigChldMode
Additional behavior configuration for SIGCHLD.
Definition SignalFdWatcher.hpp:54
@ Default
Default SIGCHLD behavior.
Definition SignalFdWatcher.hpp:55
@ NoChldWait
Request that child exit does not leave zombies (SA_NOCLDWAIT).
Definition SignalFdWatcher.hpp:57
@ NoChldStop
Do not generate SIGCHLD when children stop/continue (SA_NOCLDSTOP).
Definition SignalFdWatcher.hpp:56
Definition SocketClient.hpp:23