File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1818
1919#include < concepts>
2020#include < system_error>
21+ #include < type_traits>
2122
2223/*
2324 Signal Set Public API
@@ -224,6 +225,36 @@ class BOOST_COROSIO_DECL signal_set : public io_signal_set
224225 (check (add (signals)), ...);
225226 }
226227
228+ /* * Construct an empty signal set from an executor.
229+
230+ The signal set is associated with the executor's context.
231+
232+ @param ex The executor whose context will own this signal set.
233+ */
234+ template <class Ex >
235+ requires (!std::same_as<std::remove_cvref_t <Ex>, signal_set>) &&
236+ capy::Executor<Ex>
237+ explicit signal_set (Ex const & ex) : signal_set(ex.context())
238+ {
239+ }
240+
241+ /* * Construct a signal set with initial signals from an executor.
242+
243+ The signal set is associated with the executor's context.
244+
245+ @param ex The executor whose context will own this signal set.
246+ @param signal First signal number to add.
247+ @param signals Additional signal numbers to add.
248+
249+ @throws std::system_error Thrown on failure.
250+ */
251+ template <class Ex , std::convertible_to<int >... Signals>
252+ requires capy::Executor<Ex>
253+ signal_set (Ex const & ex, int signal, Signals... signals)
254+ : signal_set(ex.context(), signal, signals...)
255+ {
256+ }
257+
227258 /* * Move constructor.
228259
229260 Transfers ownership of the signal set resources.
Original file line number Diff line number Diff line change @@ -67,6 +67,22 @@ struct signal_set_test
6767 BOOST_TEST_PASS ();
6868 }
6969
70+ void testConstructFromExecutor ()
71+ {
72+ io_context ioc (Backend);
73+ signal_set s (ioc.get_executor ());
74+
75+ BOOST_TEST_PASS ();
76+ }
77+
78+ void testConstructFromExecutorWithSignals ()
79+ {
80+ io_context ioc (Backend);
81+ signal_set s (ioc.get_executor (), SIGINT , SIGTERM );
82+
83+ BOOST_TEST_PASS ();
84+ }
85+
7086 void testMoveConstruct ()
7187 {
7288 io_context ioc (Backend);
@@ -795,6 +811,8 @@ struct signal_set_test
795811 testConstructWithOneSignal ();
796812 testConstructWithTwoSignals ();
797813 testConstructWithThreeSignals ();
814+ testConstructFromExecutor ();
815+ testConstructFromExecutorWithSignals ();
798816 testMoveConstruct ();
799817 testMoveAssign ();
800818 testMoveAssignCrossContext ();
You can’t perform that action at this time.
0 commit comments