basic_signal_set.hpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650
  1. //
  2. // basic_signal_set.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com)
  6. //
  7. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  8. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  9. //
  10. #ifndef BOOST_ASIO_BASIC_SIGNAL_SET_HPP
  11. #define BOOST_ASIO_BASIC_SIGNAL_SET_HPP
  12. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  13. # pragma once
  14. #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
  15. #include <boost/asio/detail/config.hpp>
  16. #include <boost/asio/any_io_executor.hpp>
  17. #include <boost/asio/async_result.hpp>
  18. #include <boost/asio/detail/handler_type_requirements.hpp>
  19. #include <boost/asio/detail/io_object_impl.hpp>
  20. #include <boost/asio/detail/non_const_lvalue.hpp>
  21. #include <boost/asio/detail/signal_set_service.hpp>
  22. #include <boost/asio/detail/throw_error.hpp>
  23. #include <boost/asio/detail/type_traits.hpp>
  24. #include <boost/asio/error.hpp>
  25. #include <boost/asio/execution_context.hpp>
  26. #include <boost/asio/signal_set_base.hpp>
  27. #include <boost/asio/detail/push_options.hpp>
  28. namespace boost {
  29. namespace asio {
  30. /// Provides signal functionality.
  31. /**
  32. * The basic_signal_set class provides the ability to perform an asynchronous
  33. * wait for one or more signals to occur.
  34. *
  35. * @par Thread Safety
  36. * @e Distinct @e objects: Safe.@n
  37. * @e Shared @e objects: Unsafe.
  38. *
  39. * @par Example
  40. * Performing an asynchronous wait:
  41. * @code
  42. * void handler(
  43. * const boost::system::error_code& error,
  44. * int signal_number)
  45. * {
  46. * if (!error)
  47. * {
  48. * // A signal occurred.
  49. * }
  50. * }
  51. *
  52. * ...
  53. *
  54. * // Construct a signal set registered for process termination.
  55. * boost::asio::signal_set signals(my_context, SIGINT, SIGTERM);
  56. *
  57. * // Start an asynchronous wait for one of the signals to occur.
  58. * signals.async_wait(handler);
  59. * @endcode
  60. *
  61. * @par Queueing of signal notifications
  62. *
  63. * If a signal is registered with a signal_set, and the signal occurs when
  64. * there are no waiting handlers, then the signal notification is queued. The
  65. * next async_wait operation on that signal_set will dequeue the notification.
  66. * If multiple notifications are queued, subsequent async_wait operations
  67. * dequeue them one at a time. Signal notifications are dequeued in order of
  68. * ascending signal number.
  69. *
  70. * If a signal number is removed from a signal_set (using the @c remove or @c
  71. * erase member functions) then any queued notifications for that signal are
  72. * discarded.
  73. *
  74. * @par Multiple registration of signals
  75. *
  76. * The same signal number may be registered with different signal_set objects.
  77. * When the signal occurs, one handler is called for each signal_set object.
  78. *
  79. * Note that multiple registration only works for signals that are registered
  80. * using Asio. The application must not also register a signal handler using
  81. * functions such as @c signal() or @c sigaction().
  82. *
  83. * @par Signal masking on POSIX platforms
  84. *
  85. * POSIX allows signals to be blocked using functions such as @c sigprocmask()
  86. * and @c pthread_sigmask(). For signals to be delivered, programs must ensure
  87. * that any signals registered using signal_set objects are unblocked in at
  88. * least one thread.
  89. */
  90. template <typename Executor = any_io_executor>
  91. class basic_signal_set : public signal_set_base
  92. {
  93. private:
  94. class initiate_async_wait;
  95. public:
  96. /// The type of the executor associated with the object.
  97. typedef Executor executor_type;
  98. /// Rebinds the signal set type to another executor.
  99. template <typename Executor1>
  100. struct rebind_executor
  101. {
  102. /// The signal set type when rebound to the specified executor.
  103. typedef basic_signal_set<Executor1> other;
  104. };
  105. /// Construct a signal set without adding any signals.
  106. /**
  107. * This constructor creates a signal set without registering for any signals.
  108. *
  109. * @param ex The I/O executor that the signal set will use, by default, to
  110. * dispatch handlers for any asynchronous operations performed on the
  111. * signal set.
  112. */
  113. explicit basic_signal_set(const executor_type& ex)
  114. : impl_(0, ex)
  115. {
  116. }
  117. /// Construct a signal set without adding any signals.
  118. /**
  119. * This constructor creates a signal set without registering for any signals.
  120. *
  121. * @param context An execution context which provides the I/O executor that
  122. * the signal set will use, by default, to dispatch handlers for any
  123. * asynchronous operations performed on the signal set.
  124. */
  125. template <typename ExecutionContext>
  126. explicit basic_signal_set(ExecutionContext& context,
  127. constraint_t<
  128. is_convertible<ExecutionContext&, execution_context&>::value,
  129. defaulted_constraint
  130. > = defaulted_constraint())
  131. : impl_(0, 0, context)
  132. {
  133. }
  134. /// Construct a signal set and add one signal.
  135. /**
  136. * This constructor creates a signal set and registers for one signal.
  137. *
  138. * @param ex The I/O executor that the signal set will use, by default, to
  139. * dispatch handlers for any asynchronous operations performed on the
  140. * signal set.
  141. *
  142. * @param signal_number_1 The signal number to be added.
  143. *
  144. * @note This constructor is equivalent to performing:
  145. * @code boost::asio::signal_set signals(ex);
  146. * signals.add(signal_number_1); @endcode
  147. */
  148. basic_signal_set(const executor_type& ex, int signal_number_1)
  149. : impl_(0, ex)
  150. {
  151. boost::system::error_code ec;
  152. impl_.get_service().add(impl_.get_implementation(), signal_number_1, ec);
  153. boost::asio::detail::throw_error(ec, "add");
  154. }
  155. /// Construct a signal set and add one signal.
  156. /**
  157. * This constructor creates a signal set and registers for one signal.
  158. *
  159. * @param context An execution context which provides the I/O executor that
  160. * the signal set will use, by default, to dispatch handlers for any
  161. * asynchronous operations performed on the signal set.
  162. *
  163. * @param signal_number_1 The signal number to be added.
  164. *
  165. * @note This constructor is equivalent to performing:
  166. * @code boost::asio::signal_set signals(context);
  167. * signals.add(signal_number_1); @endcode
  168. */
  169. template <typename ExecutionContext>
  170. basic_signal_set(ExecutionContext& context, int signal_number_1,
  171. constraint_t<
  172. is_convertible<ExecutionContext&, execution_context&>::value,
  173. defaulted_constraint
  174. > = defaulted_constraint())
  175. : impl_(0, 0, context)
  176. {
  177. boost::system::error_code ec;
  178. impl_.get_service().add(impl_.get_implementation(), signal_number_1, ec);
  179. boost::asio::detail::throw_error(ec, "add");
  180. }
  181. /// Construct a signal set and add two signals.
  182. /**
  183. * This constructor creates a signal set and registers for two signals.
  184. *
  185. * @param ex The I/O executor that the signal set will use, by default, to
  186. * dispatch handlers for any asynchronous operations performed on the
  187. * signal set.
  188. *
  189. * @param signal_number_1 The first signal number to be added.
  190. *
  191. * @param signal_number_2 The second signal number to be added.
  192. *
  193. * @note This constructor is equivalent to performing:
  194. * @code boost::asio::signal_set signals(ex);
  195. * signals.add(signal_number_1);
  196. * signals.add(signal_number_2); @endcode
  197. */
  198. basic_signal_set(const executor_type& ex, int signal_number_1,
  199. int signal_number_2)
  200. : impl_(0, ex)
  201. {
  202. boost::system::error_code ec;
  203. impl_.get_service().add(impl_.get_implementation(), signal_number_1, ec);
  204. boost::asio::detail::throw_error(ec, "add");
  205. impl_.get_service().add(impl_.get_implementation(), signal_number_2, ec);
  206. boost::asio::detail::throw_error(ec, "add");
  207. }
  208. /// Construct a signal set and add two signals.
  209. /**
  210. * This constructor creates a signal set and registers for two signals.
  211. *
  212. * @param context An execution context which provides the I/O executor that
  213. * the signal set will use, by default, to dispatch handlers for any
  214. * asynchronous operations performed on the signal set.
  215. *
  216. * @param signal_number_1 The first signal number to be added.
  217. *
  218. * @param signal_number_2 The second signal number to be added.
  219. *
  220. * @note This constructor is equivalent to performing:
  221. * @code boost::asio::signal_set signals(context);
  222. * signals.add(signal_number_1);
  223. * signals.add(signal_number_2); @endcode
  224. */
  225. template <typename ExecutionContext>
  226. basic_signal_set(ExecutionContext& context, int signal_number_1,
  227. int signal_number_2,
  228. constraint_t<
  229. is_convertible<ExecutionContext&, execution_context&>::value,
  230. defaulted_constraint
  231. > = defaulted_constraint())
  232. : impl_(0, 0, context)
  233. {
  234. boost::system::error_code ec;
  235. impl_.get_service().add(impl_.get_implementation(), signal_number_1, ec);
  236. boost::asio::detail::throw_error(ec, "add");
  237. impl_.get_service().add(impl_.get_implementation(), signal_number_2, ec);
  238. boost::asio::detail::throw_error(ec, "add");
  239. }
  240. /// Construct a signal set and add three signals.
  241. /**
  242. * This constructor creates a signal set and registers for three signals.
  243. *
  244. * @param ex The I/O executor that the signal set will use, by default, to
  245. * dispatch handlers for any asynchronous operations performed on the
  246. * signal set.
  247. *
  248. * @param signal_number_1 The first signal number to be added.
  249. *
  250. * @param signal_number_2 The second signal number to be added.
  251. *
  252. * @param signal_number_3 The third signal number to be added.
  253. *
  254. * @note This constructor is equivalent to performing:
  255. * @code boost::asio::signal_set signals(ex);
  256. * signals.add(signal_number_1);
  257. * signals.add(signal_number_2);
  258. * signals.add(signal_number_3); @endcode
  259. */
  260. basic_signal_set(const executor_type& ex, int signal_number_1,
  261. int signal_number_2, int signal_number_3)
  262. : impl_(0, ex)
  263. {
  264. boost::system::error_code ec;
  265. impl_.get_service().add(impl_.get_implementation(), signal_number_1, ec);
  266. boost::asio::detail::throw_error(ec, "add");
  267. impl_.get_service().add(impl_.get_implementation(), signal_number_2, ec);
  268. boost::asio::detail::throw_error(ec, "add");
  269. impl_.get_service().add(impl_.get_implementation(), signal_number_3, ec);
  270. boost::asio::detail::throw_error(ec, "add");
  271. }
  272. /// Construct a signal set and add three signals.
  273. /**
  274. * This constructor creates a signal set and registers for three signals.
  275. *
  276. * @param context An execution context which provides the I/O executor that
  277. * the signal set will use, by default, to dispatch handlers for any
  278. * asynchronous operations performed on the signal set.
  279. *
  280. * @param signal_number_1 The first signal number to be added.
  281. *
  282. * @param signal_number_2 The second signal number to be added.
  283. *
  284. * @param signal_number_3 The third signal number to be added.
  285. *
  286. * @note This constructor is equivalent to performing:
  287. * @code boost::asio::signal_set signals(context);
  288. * signals.add(signal_number_1);
  289. * signals.add(signal_number_2);
  290. * signals.add(signal_number_3); @endcode
  291. */
  292. template <typename ExecutionContext>
  293. basic_signal_set(ExecutionContext& context, int signal_number_1,
  294. int signal_number_2, int signal_number_3,
  295. constraint_t<
  296. is_convertible<ExecutionContext&, execution_context&>::value,
  297. defaulted_constraint
  298. > = defaulted_constraint())
  299. : impl_(0, 0, context)
  300. {
  301. boost::system::error_code ec;
  302. impl_.get_service().add(impl_.get_implementation(), signal_number_1, ec);
  303. boost::asio::detail::throw_error(ec, "add");
  304. impl_.get_service().add(impl_.get_implementation(), signal_number_2, ec);
  305. boost::asio::detail::throw_error(ec, "add");
  306. impl_.get_service().add(impl_.get_implementation(), signal_number_3, ec);
  307. boost::asio::detail::throw_error(ec, "add");
  308. }
  309. /// Destroys the signal set.
  310. /**
  311. * This function destroys the signal set, cancelling any outstanding
  312. * asynchronous wait operations associated with the signal set as if by
  313. * calling @c cancel.
  314. */
  315. ~basic_signal_set()
  316. {
  317. }
  318. /// Get the executor associated with the object.
  319. const executor_type& get_executor() noexcept
  320. {
  321. return impl_.get_executor();
  322. }
  323. /// Add a signal to a signal_set.
  324. /**
  325. * This function adds the specified signal to the set. It has no effect if the
  326. * signal is already in the set.
  327. *
  328. * @param signal_number The signal to be added to the set.
  329. *
  330. * @throws boost::system::system_error Thrown on failure.
  331. */
  332. void add(int signal_number)
  333. {
  334. boost::system::error_code ec;
  335. impl_.get_service().add(impl_.get_implementation(), signal_number, ec);
  336. boost::asio::detail::throw_error(ec, "add");
  337. }
  338. /// Add a signal to a signal_set.
  339. /**
  340. * This function adds the specified signal to the set. It has no effect if the
  341. * signal is already in the set.
  342. *
  343. * @param signal_number The signal to be added to the set.
  344. *
  345. * @param ec Set to indicate what error occurred, if any.
  346. */
  347. BOOST_ASIO_SYNC_OP_VOID add(int signal_number,
  348. boost::system::error_code& ec)
  349. {
  350. impl_.get_service().add(impl_.get_implementation(), signal_number, ec);
  351. BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
  352. }
  353. /// Add a signal to a signal_set with the specified flags.
  354. /**
  355. * This function adds the specified signal to the set. It has no effect if the
  356. * signal is already in the set.
  357. *
  358. * Flags other than flags::dont_care require OS support for the @c sigaction
  359. * call, and this function will fail with @c error::operation_not_supported if
  360. * this is unavailable.
  361. *
  362. * The specified flags will conflict with a prior, active registration of the
  363. * same signal, if either specified a flags value other than flags::dont_care.
  364. * In this case, the @c add will fail with @c error::invalid_argument.
  365. *
  366. * @param signal_number The signal to be added to the set.
  367. *
  368. * @param f Flags to modify the behaviour of the specified signal.
  369. *
  370. * @throws boost::system::system_error Thrown on failure.
  371. */
  372. void add(int signal_number, flags_t f)
  373. {
  374. boost::system::error_code ec;
  375. impl_.get_service().add(impl_.get_implementation(), signal_number, f, ec);
  376. boost::asio::detail::throw_error(ec, "add");
  377. }
  378. /// Add a signal to a signal_set with the specified flags.
  379. /**
  380. * This function adds the specified signal to the set. It has no effect if the
  381. * signal is already in the set.
  382. *
  383. * Flags other than flags::dont_care require OS support for the @c sigaction
  384. * call, and this function will fail with @c error::operation_not_supported if
  385. * this is unavailable.
  386. *
  387. * The specified flags will conflict with a prior, active registration of the
  388. * same signal, if either specified a flags value other than flags::dont_care.
  389. * In this case, the @c add will fail with @c error::invalid_argument.
  390. *
  391. * @param signal_number The signal to be added to the set.
  392. *
  393. * @param f Flags to modify the behaviour of the specified signal.
  394. *
  395. * @param ec Set to indicate what error occurred, if any.
  396. */
  397. BOOST_ASIO_SYNC_OP_VOID add(int signal_number, flags_t f,
  398. boost::system::error_code& ec)
  399. {
  400. impl_.get_service().add(impl_.get_implementation(), signal_number, f, ec);
  401. BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
  402. }
  403. /// Remove a signal from a signal_set.
  404. /**
  405. * This function removes the specified signal from the set. It has no effect
  406. * if the signal is not in the set.
  407. *
  408. * @param signal_number The signal to be removed from the set.
  409. *
  410. * @throws boost::system::system_error Thrown on failure.
  411. *
  412. * @note Removes any notifications that have been queued for the specified
  413. * signal number.
  414. */
  415. void remove(int signal_number)
  416. {
  417. boost::system::error_code ec;
  418. impl_.get_service().remove(impl_.get_implementation(), signal_number, ec);
  419. boost::asio::detail::throw_error(ec, "remove");
  420. }
  421. /// Remove a signal from a signal_set.
  422. /**
  423. * This function removes the specified signal from the set. It has no effect
  424. * if the signal is not in the set.
  425. *
  426. * @param signal_number The signal to be removed from the set.
  427. *
  428. * @param ec Set to indicate what error occurred, if any.
  429. *
  430. * @note Removes any notifications that have been queued for the specified
  431. * signal number.
  432. */
  433. BOOST_ASIO_SYNC_OP_VOID remove(int signal_number,
  434. boost::system::error_code& ec)
  435. {
  436. impl_.get_service().remove(impl_.get_implementation(), signal_number, ec);
  437. BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
  438. }
  439. /// Remove all signals from a signal_set.
  440. /**
  441. * This function removes all signals from the set. It has no effect if the set
  442. * is already empty.
  443. *
  444. * @throws boost::system::system_error Thrown on failure.
  445. *
  446. * @note Removes all queued notifications.
  447. */
  448. void clear()
  449. {
  450. boost::system::error_code ec;
  451. impl_.get_service().clear(impl_.get_implementation(), ec);
  452. boost::asio::detail::throw_error(ec, "clear");
  453. }
  454. /// Remove all signals from a signal_set.
  455. /**
  456. * This function removes all signals from the set. It has no effect if the set
  457. * is already empty.
  458. *
  459. * @param ec Set to indicate what error occurred, if any.
  460. *
  461. * @note Removes all queued notifications.
  462. */
  463. BOOST_ASIO_SYNC_OP_VOID clear(boost::system::error_code& ec)
  464. {
  465. impl_.get_service().clear(impl_.get_implementation(), ec);
  466. BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
  467. }
  468. /// Cancel all operations associated with the signal set.
  469. /**
  470. * This function forces the completion of any pending asynchronous wait
  471. * operations against the signal set. The handler for each cancelled
  472. * operation will be invoked with the boost::asio::error::operation_aborted
  473. * error code.
  474. *
  475. * Cancellation does not alter the set of registered signals.
  476. *
  477. * @throws boost::system::system_error Thrown on failure.
  478. *
  479. * @note If a registered signal occurred before cancel() is called, then the
  480. * handlers for asynchronous wait operations will:
  481. *
  482. * @li have already been invoked; or
  483. *
  484. * @li have been queued for invocation in the near future.
  485. *
  486. * These handlers can no longer be cancelled, and therefore are passed an
  487. * error code that indicates the successful completion of the wait operation.
  488. */
  489. void cancel()
  490. {
  491. boost::system::error_code ec;
  492. impl_.get_service().cancel(impl_.get_implementation(), ec);
  493. boost::asio::detail::throw_error(ec, "cancel");
  494. }
  495. /// Cancel all operations associated with the signal set.
  496. /**
  497. * This function forces the completion of any pending asynchronous wait
  498. * operations against the signal set. The handler for each cancelled
  499. * operation will be invoked with the boost::asio::error::operation_aborted
  500. * error code.
  501. *
  502. * Cancellation does not alter the set of registered signals.
  503. *
  504. * @param ec Set to indicate what error occurred, if any.
  505. *
  506. * @note If a registered signal occurred before cancel() is called, then the
  507. * handlers for asynchronous wait operations will:
  508. *
  509. * @li have already been invoked; or
  510. *
  511. * @li have been queued for invocation in the near future.
  512. *
  513. * These handlers can no longer be cancelled, and therefore are passed an
  514. * error code that indicates the successful completion of the wait operation.
  515. */
  516. BOOST_ASIO_SYNC_OP_VOID cancel(boost::system::error_code& ec)
  517. {
  518. impl_.get_service().cancel(impl_.get_implementation(), ec);
  519. BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
  520. }
  521. /// Start an asynchronous operation to wait for a signal to be delivered.
  522. /**
  523. * This function may be used to initiate an asynchronous wait against the
  524. * signal set. It is an initiating function for an @ref
  525. * asynchronous_operation, and always returns immediately.
  526. *
  527. * For each call to async_wait(), the completion handler will be called
  528. * exactly once. The completion handler will be called when:
  529. *
  530. * @li One of the registered signals in the signal set occurs; or
  531. *
  532. * @li The signal set was cancelled, in which case the handler is passed the
  533. * error code boost::asio::error::operation_aborted.
  534. *
  535. * @param token The @ref completion_token that will be used to produce a
  536. * completion handler, which will be called when the wait completes.
  537. * Potential completion tokens include @ref use_future, @ref use_awaitable,
  538. * @ref yield_context, or a function object with the correct completion
  539. * signature. The function signature of the completion handler must be:
  540. * @code void handler(
  541. * const boost::system::error_code& error, // Result of operation.
  542. * int signal_number // Indicates which signal occurred.
  543. * ); @endcode
  544. * Regardless of whether the asynchronous operation completes immediately or
  545. * not, the completion handler will not be invoked from within this function.
  546. * On immediate completion, invocation of the handler will be performed in a
  547. * manner equivalent to using boost::asio::post().
  548. *
  549. * @par Completion Signature
  550. * @code void(boost::system::error_code, int) @endcode
  551. *
  552. * @par Per-Operation Cancellation
  553. * This asynchronous operation supports cancellation for the following
  554. * boost::asio::cancellation_type values:
  555. *
  556. * @li @c cancellation_type::terminal
  557. *
  558. * @li @c cancellation_type::partial
  559. *
  560. * @li @c cancellation_type::total
  561. */
  562. template <
  563. BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code, int))
  564. SignalToken = default_completion_token_t<executor_type>>
  565. auto async_wait(
  566. SignalToken&& token = default_completion_token_t<executor_type>())
  567. -> decltype(
  568. async_initiate<SignalToken, void (boost::system::error_code, int)>(
  569. declval<initiate_async_wait>(), token))
  570. {
  571. return async_initiate<SignalToken, void (boost::system::error_code, int)>(
  572. initiate_async_wait(this), token);
  573. }
  574. private:
  575. // Disallow copying and assignment.
  576. basic_signal_set(const basic_signal_set&) = delete;
  577. basic_signal_set& operator=(const basic_signal_set&) = delete;
  578. class initiate_async_wait
  579. {
  580. public:
  581. typedef Executor executor_type;
  582. explicit initiate_async_wait(basic_signal_set* self)
  583. : self_(self)
  584. {
  585. }
  586. const executor_type& get_executor() const noexcept
  587. {
  588. return self_->get_executor();
  589. }
  590. template <typename SignalHandler>
  591. void operator()(SignalHandler&& handler) const
  592. {
  593. // If you get an error on the following line it means that your handler
  594. // does not meet the documented type requirements for a SignalHandler.
  595. BOOST_ASIO_SIGNAL_HANDLER_CHECK(SignalHandler, handler) type_check;
  596. detail::non_const_lvalue<SignalHandler> handler2(handler);
  597. self_->impl_.get_service().async_wait(
  598. self_->impl_.get_implementation(),
  599. handler2.value, self_->impl_.get_executor());
  600. }
  601. private:
  602. basic_signal_set* self_;
  603. };
  604. detail::io_object_impl<detail::signal_set_service, Executor> impl_;
  605. };
  606. } // namespace asio
  607. } // namespace boost
  608. #include <boost/asio/detail/pop_options.hpp>
  609. #endif // BOOST_ASIO_BASIC_SIGNAL_SET_HPP