2 // signal_set_service.hpp
3 // ~~~~~~~~~~~~~~~~~~~~~~
5 // Copyright (c) 2003-2016 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>
19 #include <boost/asio/async_result.hpp>
20 #include <boost/asio/detail/signal_set_service.hpp>
21 #include <boost/asio/error.hpp>
22 #include <boost/asio/io_service.hpp>
24 #include <boost/asio/detail/push_options.hpp>
29 /// Default service implementation for a signal set.
30 class signal_set_service
31 #if defined(GENERATING_DOCUMENTATION)
32 : public boost::asio::io_service::service
34 : public boost::asio::detail::service_base<signal_set_service>
38 #if defined(GENERATING_DOCUMENTATION)
39 /// The unique service identifier.
40 static boost::asio::io_service::id id;
44 /// The type of a signal set implementation.
45 #if defined(GENERATING_DOCUMENTATION)
46 typedef implementation_defined implementation_type;
48 typedef detail::signal_set_service::implementation_type implementation_type;
51 /// Construct a new signal set service for the specified io_service.
52 explicit signal_set_service(boost::asio::io_service& io_service)
53 : boost::asio::detail::service_base<signal_set_service>(io_service),
54 service_impl_(io_service)
58 /// Construct a new signal set implementation.
59 void construct(implementation_type& impl)
61 service_impl_.construct(impl);
64 /// Destroy a signal set implementation.
65 void destroy(implementation_type& impl)
67 service_impl_.destroy(impl);
70 /// Add a signal to a signal_set.
71 boost::system::error_code add(implementation_type& impl,
72 int signal_number, boost::system::error_code& ec)
74 return service_impl_.add(impl, signal_number, ec);
77 /// Remove a signal to a signal_set.
78 boost::system::error_code remove(implementation_type& impl,
79 int signal_number, boost::system::error_code& ec)
81 return service_impl_.remove(impl, signal_number, ec);
84 /// Remove all signals from a signal_set.
85 boost::system::error_code clear(implementation_type& impl,
86 boost::system::error_code& ec)
88 return service_impl_.clear(impl, ec);
91 /// Cancel all operations associated with the signal set.
92 boost::system::error_code cancel(implementation_type& impl,
93 boost::system::error_code& ec)
95 return service_impl_.cancel(impl, ec);
98 // Start an asynchronous operation to wait for a signal to be delivered.
99 template <typename SignalHandler>
100 BOOST_ASIO_INITFN_RESULT_TYPE(SignalHandler,
101 void (boost::system::error_code, int))
102 async_wait(implementation_type& impl,
103 BOOST_ASIO_MOVE_ARG(SignalHandler) handler)
105 detail::async_result_init<
106 SignalHandler, void (boost::system::error_code, int)> init(
107 BOOST_ASIO_MOVE_CAST(SignalHandler)(handler));
109 service_impl_.async_wait(impl, init.handler);
111 return init.result.get();
115 // Destroy all user-defined handler objects owned by the service.
116 void shutdown_service()
118 service_impl_.shutdown_service();
121 // Perform any fork-related housekeeping.
122 void fork_service(boost::asio::io_service::fork_event event)
124 service_impl_.fork_service(event);
127 // The platform-specific implementation.
128 detail::signal_set_service service_impl_;
134 #include <boost/asio/detail/pop_options.hpp>
136 #endif // BOOST_ASIO_SIGNAL_SET_SERVICE_HPP