2 // signal_set_service.hpp
3 // ~~~~~~~~~~~~~~~~~~~~~~
5 // Copyright (c) 2003-2018 Christopher M. Kohlhoff (chris at kohlhoff dot com)
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)
11 #ifndef BOOST_ASIO_SIGNAL_SET_SERVICE_HPP
12 #define BOOST_ASIO_SIGNAL_SET_SERVICE_HPP
14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
18 #include <boost/asio/detail/config.hpp>
20 #if defined(BOOST_ASIO_ENABLE_OLD_SERVICES)
22 #include <boost/asio/async_result.hpp>
23 #include <boost/asio/detail/signal_set_service.hpp>
24 #include <boost/asio/error.hpp>
25 #include <boost/asio/io_context.hpp>
27 #include <boost/asio/detail/push_options.hpp>
32 /// Default service implementation for a signal set.
33 class signal_set_service
34 #if defined(GENERATING_DOCUMENTATION)
35 : public boost::asio::io_context::service
37 : public boost::asio::detail::service_base<signal_set_service>
41 #if defined(GENERATING_DOCUMENTATION)
42 /// The unique service identifier.
43 static boost::asio::io_context::id id;
47 /// The type of a signal set implementation.
48 #if defined(GENERATING_DOCUMENTATION)
49 typedef implementation_defined implementation_type;
51 typedef detail::signal_set_service::implementation_type implementation_type;
54 /// Construct a new signal set service for the specified io_context.
55 explicit signal_set_service(boost::asio::io_context& io_context)
56 : boost::asio::detail::service_base<signal_set_service>(io_context),
57 service_impl_(io_context)
61 /// Construct a new signal set implementation.
62 void construct(implementation_type& impl)
64 service_impl_.construct(impl);
67 /// Destroy a signal set implementation.
68 void destroy(implementation_type& impl)
70 service_impl_.destroy(impl);
73 /// Add a signal to a signal_set.
74 BOOST_ASIO_SYNC_OP_VOID add(implementation_type& impl,
75 int signal_number, boost::system::error_code& ec)
77 service_impl_.add(impl, signal_number, ec);
78 BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
81 /// Remove a signal to a signal_set.
82 BOOST_ASIO_SYNC_OP_VOID remove(implementation_type& impl,
83 int signal_number, boost::system::error_code& ec)
85 service_impl_.remove(impl, signal_number, ec);
86 BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
89 /// Remove all signals from a signal_set.
90 BOOST_ASIO_SYNC_OP_VOID clear(implementation_type& impl,
91 boost::system::error_code& ec)
93 service_impl_.clear(impl, ec);
94 BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
97 /// Cancel all operations associated with the signal set.
98 BOOST_ASIO_SYNC_OP_VOID cancel(implementation_type& impl,
99 boost::system::error_code& ec)
101 service_impl_.cancel(impl, ec);
102 BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
105 // Start an asynchronous operation to wait for a signal to be delivered.
106 template <typename SignalHandler>
107 BOOST_ASIO_INITFN_RESULT_TYPE(SignalHandler,
108 void (boost::system::error_code, int))
109 async_wait(implementation_type& impl,
110 BOOST_ASIO_MOVE_ARG(SignalHandler) handler)
112 async_completion<SignalHandler,
113 void (boost::system::error_code, int)> init(handler);
115 service_impl_.async_wait(impl, init.completion_handler);
117 return init.result.get();
121 // Destroy all user-defined handler objects owned by the service.
124 service_impl_.shutdown();
127 // Perform any fork-related housekeeping.
128 void notify_fork(boost::asio::io_context::fork_event event)
130 service_impl_.notify_fork(event);
133 // The platform-specific implementation.
134 detail::signal_set_service service_impl_;
140 #include <boost/asio/detail/pop_options.hpp>
142 #endif // defined(BOOST_ASIO_ENABLE_OLD_SERVICES)
144 #endif // BOOST_ASIO_SIGNAL_SET_SERVICE_HPP