summaryrefslogtreecommitdiff
path: root/boost/asio/basic_signal_set.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'boost/asio/basic_signal_set.hpp')
-rw-r--r--boost/asio/basic_signal_set.hpp272
1 files changed, 211 insertions, 61 deletions
diff --git a/boost/asio/basic_signal_set.hpp b/boost/asio/basic_signal_set.hpp
index 8ca5dfa1d9..175b4f4832 100644
--- a/boost/asio/basic_signal_set.hpp
+++ b/boost/asio/basic_signal_set.hpp
@@ -2,7 +2,7 @@
// basic_signal_set.hpp
// ~~~~~~~~~~~~~~~~~~~~
//
-// Copyright (c) 2003-2018 Christopher M. Kohlhoff (chris at kohlhoff dot com)
+// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
@@ -17,25 +17,24 @@
#include <boost/asio/detail/config.hpp>
-#if defined(BOOST_ASIO_ENABLE_OLD_SERVICES)
-
-#include <boost/asio/basic_io_object.hpp>
+#include <boost/asio/async_result.hpp>
#include <boost/asio/detail/handler_type_requirements.hpp>
+#include <boost/asio/detail/io_object_impl.hpp>
+#include <boost/asio/detail/non_const_lvalue.hpp>
+#include <boost/asio/detail/signal_set_service.hpp>
#include <boost/asio/detail/throw_error.hpp>
+#include <boost/asio/detail/type_traits.hpp>
#include <boost/asio/error.hpp>
-#include <boost/asio/signal_set_service.hpp>
-
-#include <boost/asio/detail/push_options.hpp>
+#include <boost/asio/execution_context.hpp>
+#include <boost/asio/executor.hpp>
namespace boost {
namespace asio {
/// Provides signal functionality.
/**
- * The basic_signal_set class template provides the ability to perform an
- * asynchronous wait for one or more signals to occur.
- *
- * Most applications will use the boost::asio::signal_set typedef.
+ * The basic_signal_set class provides the ability to perform an asynchronous
+ * wait for one or more signals to occur.
*
* @par Thread Safety
* @e Distinct @e objects: Safe.@n
@@ -57,7 +56,7 @@ namespace asio {
* ...
*
* // Construct a signal set registered for process termination.
- * boost::asio::signal_set signals(io_context, SIGINT, SIGTERM);
+ * boost::asio::signal_set signals(my_context, SIGINT, SIGTERM);
*
* // Start an asynchronous wait for one of the signals to occur.
* signals.async_wait(handler);
@@ -92,20 +91,40 @@ namespace asio {
* that any signals registered using signal_set objects are unblocked in at
* least one thread.
*/
-template <typename SignalSetService = signal_set_service>
+template <typename Executor = executor>
class basic_signal_set
- : public basic_io_object<SignalSetService>
{
public:
+ /// The type of the executor associated with the object.
+ typedef Executor executor_type;
+
+ /// Construct a signal set without adding any signals.
+ /**
+ * This constructor creates a signal set without registering for any signals.
+ *
+ * @param ex The I/O executor that the signal set will use, by default, to
+ * dispatch handlers for any asynchronous operations performed on the
+ * signal set.
+ */
+ explicit basic_signal_set(const executor_type& ex)
+ : impl_(ex)
+ {
+ }
+
/// Construct a signal set without adding any signals.
/**
* This constructor creates a signal set without registering for any signals.
*
- * @param io_context The io_context object that the signal set will use to
- * dispatch handlers for any asynchronous operations performed on the set.
+ * @param context An execution context which provides the I/O executor that
+ * the signal set will use, by default, to dispatch handlers for any
+ * asynchronous operations performed on the signal set.
*/
- explicit basic_signal_set(boost::asio::io_context& io_context)
- : basic_io_object<SignalSetService>(io_context)
+ template <typename ExecutionContext>
+ explicit basic_signal_set(ExecutionContext& context,
+ typename enable_if<
+ is_convertible<ExecutionContext&, execution_context&>::value
+ >::type* = 0)
+ : impl_(context)
{
}
@@ -113,20 +132,47 @@ public:
/**
* This constructor creates a signal set and registers for one signal.
*
- * @param io_context The io_context object that the signal set will use to
- * dispatch handlers for any asynchronous operations performed on the set.
+ * @param ex The I/O executor that the signal set will use, by default, to
+ * dispatch handlers for any asynchronous operations performed on the
+ * signal set.
*
* @param signal_number_1 The signal number to be added.
*
* @note This constructor is equivalent to performing:
- * @code boost::asio::signal_set signals(io_context);
+ * @code boost::asio::signal_set signals(ex);
* signals.add(signal_number_1); @endcode
*/
- basic_signal_set(boost::asio::io_context& io_context, int signal_number_1)
- : basic_io_object<SignalSetService>(io_context)
+ basic_signal_set(const executor_type& ex, int signal_number_1)
+ : impl_(ex)
{
boost::system::error_code ec;
- this->get_service().add(this->get_implementation(), signal_number_1, ec);
+ impl_.get_service().add(impl_.get_implementation(), signal_number_1, ec);
+ boost::asio::detail::throw_error(ec, "add");
+ }
+
+ /// Construct a signal set and add one signal.
+ /**
+ * This constructor creates a signal set and registers for one signal.
+ *
+ * @param context An execution context which provides the I/O executor that
+ * the signal set will use, by default, to dispatch handlers for any
+ * asynchronous operations performed on the signal set.
+ *
+ * @param signal_number_1 The signal number to be added.
+ *
+ * @note This constructor is equivalent to performing:
+ * @code boost::asio::signal_set signals(context);
+ * signals.add(signal_number_1); @endcode
+ */
+ template <typename ExecutionContext>
+ basic_signal_set(ExecutionContext& context, int signal_number_1,
+ typename enable_if<
+ is_convertible<ExecutionContext&, execution_context&>::value
+ >::type* = 0)
+ : impl_(context)
+ {
+ boost::system::error_code ec;
+ impl_.get_service().add(impl_.get_implementation(), signal_number_1, ec);
boost::asio::detail::throw_error(ec, "add");
}
@@ -134,26 +180,59 @@ public:
/**
* This constructor creates a signal set and registers for two signals.
*
- * @param io_context The io_context object that the signal set will use to
- * dispatch handlers for any asynchronous operations performed on the set.
+ * @param ex The I/O executor that the signal set will use, by default, to
+ * dispatch handlers for any asynchronous operations performed on the
+ * signal set.
*
* @param signal_number_1 The first signal number to be added.
*
* @param signal_number_2 The second signal number to be added.
*
* @note This constructor is equivalent to performing:
- * @code boost::asio::signal_set signals(io_context);
+ * @code boost::asio::signal_set signals(ex);
* signals.add(signal_number_1);
* signals.add(signal_number_2); @endcode
*/
- basic_signal_set(boost::asio::io_context& io_context, int signal_number_1,
+ basic_signal_set(const executor_type& ex, int signal_number_1,
int signal_number_2)
- : basic_io_object<SignalSetService>(io_context)
+ : impl_(ex)
+ {
+ boost::system::error_code ec;
+ impl_.get_service().add(impl_.get_implementation(), signal_number_1, ec);
+ boost::asio::detail::throw_error(ec, "add");
+ impl_.get_service().add(impl_.get_implementation(), signal_number_2, ec);
+ boost::asio::detail::throw_error(ec, "add");
+ }
+
+ /// Construct a signal set and add two signals.
+ /**
+ * This constructor creates a signal set and registers for two signals.
+ *
+ * @param context An execution context which provides the I/O executor that
+ * the signal set will use, by default, to dispatch handlers for any
+ * asynchronous operations performed on the signal set.
+ *
+ * @param signal_number_1 The first signal number to be added.
+ *
+ * @param signal_number_2 The second signal number to be added.
+ *
+ * @note This constructor is equivalent to performing:
+ * @code boost::asio::signal_set signals(context);
+ * signals.add(signal_number_1);
+ * signals.add(signal_number_2); @endcode
+ */
+ template <typename ExecutionContext>
+ basic_signal_set(ExecutionContext& context, int signal_number_1,
+ int signal_number_2,
+ typename enable_if<
+ is_convertible<ExecutionContext&, execution_context&>::value
+ >::type* = 0)
+ : impl_(context)
{
boost::system::error_code ec;
- this->get_service().add(this->get_implementation(), signal_number_1, ec);
+ impl_.get_service().add(impl_.get_implementation(), signal_number_1, ec);
boost::asio::detail::throw_error(ec, "add");
- this->get_service().add(this->get_implementation(), signal_number_2, ec);
+ impl_.get_service().add(impl_.get_implementation(), signal_number_2, ec);
boost::asio::detail::throw_error(ec, "add");
}
@@ -161,8 +240,9 @@ public:
/**
* This constructor creates a signal set and registers for three signals.
*
- * @param io_context The io_context object that the signal set will use to
- * dispatch handlers for any asynchronous operations performed on the set.
+ * @param ex The I/O executor that the signal set will use, by default, to
+ * dispatch handlers for any asynchronous operations performed on the
+ * signal set.
*
* @param signal_number_1 The first signal number to be added.
*
@@ -171,24 +251,77 @@ public:
* @param signal_number_3 The third signal number to be added.
*
* @note This constructor is equivalent to performing:
- * @code boost::asio::signal_set signals(io_context);
+ * @code boost::asio::signal_set signals(ex);
* signals.add(signal_number_1);
* signals.add(signal_number_2);
* signals.add(signal_number_3); @endcode
*/
- basic_signal_set(boost::asio::io_context& io_context, int signal_number_1,
+ basic_signal_set(const executor_type& ex, int signal_number_1,
int signal_number_2, int signal_number_3)
- : basic_io_object<SignalSetService>(io_context)
+ : impl_(ex)
{
boost::system::error_code ec;
- this->get_service().add(this->get_implementation(), signal_number_1, ec);
+ impl_.get_service().add(impl_.get_implementation(), signal_number_1, ec);
boost::asio::detail::throw_error(ec, "add");
- this->get_service().add(this->get_implementation(), signal_number_2, ec);
+ impl_.get_service().add(impl_.get_implementation(), signal_number_2, ec);
boost::asio::detail::throw_error(ec, "add");
- this->get_service().add(this->get_implementation(), signal_number_3, ec);
+ impl_.get_service().add(impl_.get_implementation(), signal_number_3, ec);
boost::asio::detail::throw_error(ec, "add");
}
+ /// Construct a signal set and add three signals.
+ /**
+ * This constructor creates a signal set and registers for three signals.
+ *
+ * @param context An execution context which provides the I/O executor that
+ * the signal set will use, by default, to dispatch handlers for any
+ * asynchronous operations performed on the signal set.
+ *
+ * @param signal_number_1 The first signal number to be added.
+ *
+ * @param signal_number_2 The second signal number to be added.
+ *
+ * @param signal_number_3 The third signal number to be added.
+ *
+ * @note This constructor is equivalent to performing:
+ * @code boost::asio::signal_set signals(context);
+ * signals.add(signal_number_1);
+ * signals.add(signal_number_2);
+ * signals.add(signal_number_3); @endcode
+ */
+ template <typename ExecutionContext>
+ basic_signal_set(ExecutionContext& context, int signal_number_1,
+ int signal_number_2, int signal_number_3,
+ typename enable_if<
+ is_convertible<ExecutionContext&, execution_context&>::value
+ >::type* = 0)
+ : impl_(context)
+ {
+ boost::system::error_code ec;
+ impl_.get_service().add(impl_.get_implementation(), signal_number_1, ec);
+ boost::asio::detail::throw_error(ec, "add");
+ impl_.get_service().add(impl_.get_implementation(), signal_number_2, ec);
+ boost::asio::detail::throw_error(ec, "add");
+ impl_.get_service().add(impl_.get_implementation(), signal_number_3, ec);
+ boost::asio::detail::throw_error(ec, "add");
+ }
+
+ /// Destroys the signal set.
+ /**
+ * This function destroys the signal set, cancelling any outstanding
+ * asynchronous wait operations associated with the signal set as if by
+ * calling @c cancel.
+ */
+ ~basic_signal_set()
+ {
+ }
+
+ /// Get the executor associated with the object.
+ executor_type get_executor() BOOST_ASIO_NOEXCEPT
+ {
+ return impl_.get_executor();
+ }
+
/// Add a signal to a signal_set.
/**
* This function adds the specified signal to the set. It has no effect if the
@@ -201,7 +334,7 @@ public:
void add(int signal_number)
{
boost::system::error_code ec;
- this->get_service().add(this->get_implementation(), signal_number, ec);
+ impl_.get_service().add(impl_.get_implementation(), signal_number, ec);
boost::asio::detail::throw_error(ec, "add");
}
@@ -214,9 +347,10 @@ public:
*
* @param ec Set to indicate what error occurred, if any.
*/
- BOOST_ASIO_SYNC_OP_VOID add(int signal_number, boost::system::error_code& ec)
+ BOOST_ASIO_SYNC_OP_VOID add(int signal_number,
+ boost::system::error_code& ec)
{
- this->get_service().add(this->get_implementation(), signal_number, ec);
+ impl_.get_service().add(impl_.get_implementation(), signal_number, ec);
BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
}
@@ -235,7 +369,7 @@ public:
void remove(int signal_number)
{
boost::system::error_code ec;
- this->get_service().remove(this->get_implementation(), signal_number, ec);
+ impl_.get_service().remove(impl_.get_implementation(), signal_number, ec);
boost::asio::detail::throw_error(ec, "remove");
}
@@ -254,7 +388,7 @@ public:
BOOST_ASIO_SYNC_OP_VOID remove(int signal_number,
boost::system::error_code& ec)
{
- this->get_service().remove(this->get_implementation(), signal_number, ec);
+ impl_.get_service().remove(impl_.get_implementation(), signal_number, ec);
BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
}
@@ -270,7 +404,7 @@ public:
void clear()
{
boost::system::error_code ec;
- this->get_service().clear(this->get_implementation(), ec);
+ impl_.get_service().clear(impl_.get_implementation(), ec);
boost::asio::detail::throw_error(ec, "clear");
}
@@ -285,7 +419,7 @@ public:
*/
BOOST_ASIO_SYNC_OP_VOID clear(boost::system::error_code& ec)
{
- this->get_service().clear(this->get_implementation(), ec);
+ impl_.get_service().clear(impl_.get_implementation(), ec);
BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
}
@@ -313,7 +447,7 @@ public:
void cancel()
{
boost::system::error_code ec;
- this->get_service().cancel(this->get_implementation(), ec);
+ impl_.get_service().cancel(impl_.get_implementation(), ec);
boost::asio::detail::throw_error(ec, "cancel");
}
@@ -340,7 +474,7 @@ public:
*/
BOOST_ASIO_SYNC_OP_VOID cancel(boost::system::error_code& ec)
{
- this->get_service().cancel(this->get_implementation(), ec);
+ impl_.get_service().cancel(impl_.get_implementation(), ec);
BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
}
@@ -365,29 +499,45 @@ public:
* int signal_number // Indicates which signal occurred.
* ); @endcode
* Regardless of whether the asynchronous operation completes immediately or
- * not, the handler will not be invoked from within this function. Invocation
- * of the handler will be performed in a manner equivalent to using
- * boost::asio::io_context::post().
+ * not, the handler will not be invoked from within this function. On
+ * immediate completion, invocation of the handler will be performed in a
+ * manner equivalent to using boost::asio::post().
*/
template <typename SignalHandler>
BOOST_ASIO_INITFN_RESULT_TYPE(SignalHandler,
void (boost::system::error_code, int))
async_wait(BOOST_ASIO_MOVE_ARG(SignalHandler) handler)
{
- // If you get an error on the following line it means that your handler does
- // not meet the documented type requirements for a SignalHandler.
- BOOST_ASIO_SIGNAL_HANDLER_CHECK(SignalHandler, handler) type_check;
-
- return this->get_service().async_wait(this->get_implementation(),
- BOOST_ASIO_MOVE_CAST(SignalHandler)(handler));
+ return async_initiate<SignalHandler, void (boost::system::error_code, int)>(
+ initiate_async_wait(), handler, this);
}
+
+private:
+ // Disallow copying and assignment.
+ basic_signal_set(const basic_signal_set&) BOOST_ASIO_DELETED;
+ basic_signal_set& operator=(const basic_signal_set&) BOOST_ASIO_DELETED;
+
+ struct initiate_async_wait
+ {
+ template <typename SignalHandler>
+ void operator()(BOOST_ASIO_MOVE_ARG(SignalHandler) handler,
+ basic_signal_set* self) const
+ {
+ // If you get an error on the following line it means that your handler
+ // does not meet the documented type requirements for a SignalHandler.
+ BOOST_ASIO_SIGNAL_HANDLER_CHECK(SignalHandler, handler) type_check;
+
+ detail::non_const_lvalue<SignalHandler> handler2(handler);
+ self->impl_.get_service().async_wait(
+ self->impl_.get_implementation(), handler2.value,
+ self->impl_.get_implementation_executor());
+ }
+ };
+
+ detail::io_object_impl<detail::signal_set_service, Executor> impl_;
};
} // namespace asio
} // namespace boost
-#include <boost/asio/detail/pop_options.hpp>
-
-#endif // defined(BOOST_ASIO_ENABLE_OLD_SERVICES)
-
#endif // BOOST_ASIO_BASIC_SIGNAL_SET_HPP