diff options
Diffstat (limited to '3rdparty/asio/include/asio/detail/signal_set_service.hpp')
-rw-r--r-- | 3rdparty/asio/include/asio/detail/signal_set_service.hpp | 105 |
1 files changed, 90 insertions, 15 deletions
diff --git a/3rdparty/asio/include/asio/detail/signal_set_service.hpp b/3rdparty/asio/include/asio/detail/signal_set_service.hpp index 58ee99baf3b..142ff43851a 100644 --- a/3rdparty/asio/include/asio/detail/signal_set_service.hpp +++ b/3rdparty/asio/include/asio/detail/signal_set_service.hpp @@ -2,7 +2,7 @@ // detail/signal_set_service.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // -// Copyright (c) 2003-2016 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// Copyright (c) 2003-2024 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) @@ -19,8 +19,11 @@ #include <cstddef> #include <signal.h> +#include "asio/associated_cancellation_slot.hpp" +#include "asio/cancellation_type.hpp" #include "asio/error.hpp" -#include "asio/io_context.hpp" +#include "asio/execution_context.hpp" +#include "asio/signal_set_base.hpp" #include "asio/detail/handler_alloc_helpers.hpp" #include "asio/detail/memory.hpp" #include "asio/detail/op_queue.hpp" @@ -28,8 +31,18 @@ #include "asio/detail/signal_op.hpp" #include "asio/detail/socket_types.hpp" +#if defined(ASIO_HAS_IOCP) +# include "asio/detail/win_iocp_io_context.hpp" +#else // defined(ASIO_HAS_IOCP) +# include "asio/detail/scheduler.hpp" +#endif // defined(ASIO_HAS_IOCP) + #if !defined(ASIO_WINDOWS) && !defined(__CYGWIN__) -# include "asio/detail/reactor.hpp" +# if defined(ASIO_HAS_IO_URING_AS_DEFAULT) +# include "asio/detail/io_uring_service.hpp" +# else // defined(ASIO_HAS_IO_URING_AS_DEFAULT) +# include "asio/detail/reactor.hpp" +# endif // defined(ASIO_HAS_IO_URING_AS_DEFAULT) #endif // !defined(ASIO_WINDOWS) && !defined(__CYGWIN__) #include "asio/detail/push_options.hpp" @@ -48,7 +61,7 @@ extern ASIO_DECL struct signal_state* get_signal_state(); extern "C" ASIO_DECL void asio_signal_handler(int signal_number); class signal_set_service : - public service_base<signal_set_service> + public execution_context_service_base<signal_set_service> { public: // Type used for tracking an individual signal registration. @@ -109,7 +122,7 @@ public: }; // Constructor. - ASIO_DECL signal_set_service(asio::io_context& io_context); + ASIO_DECL signal_set_service(execution_context& context); // Destructor. ASIO_DECL ~signal_set_service(); @@ -119,7 +132,7 @@ public: // Perform fork-related housekeeping. ASIO_DECL void notify_fork( - asio::io_context::fork_event fork_ev); + asio::execution_context::fork_event fork_ev); // Construct a new signal_set implementation. ASIO_DECL void construct(implementation_type& impl); @@ -128,8 +141,16 @@ public: ASIO_DECL void destroy(implementation_type& impl); // Add a signal to a signal_set. + asio::error_code add(implementation_type& impl, + int signal_number, asio::error_code& ec) + { + return add(impl, signal_number, signal_set_base::flags::dont_care, ec); + } + + // Add a signal to a signal_set with the specified flags. ASIO_DECL asio::error_code add(implementation_type& impl, - int signal_number, asio::error_code& ec); + int signal_number, signal_set_base::flags_t f, + asio::error_code& ec); // Remove a signal to a signal_set. ASIO_DECL asio::error_code remove(implementation_type& impl, @@ -143,17 +164,32 @@ public: ASIO_DECL asio::error_code cancel(implementation_type& impl, asio::error_code& ec); + // Cancel a specific operation associated with the signal set. + ASIO_DECL void cancel_ops_by_key(implementation_type& impl, + void* cancellation_key); + // Start an asynchronous operation to wait for a signal to be delivered. - template <typename Handler> - void async_wait(implementation_type& impl, Handler& handler) + template <typename Handler, typename IoExecutor> + void async_wait(implementation_type& impl, + Handler& handler, const IoExecutor& io_ex) { + associated_cancellation_slot_t<Handler> slot + = asio::get_associated_cancellation_slot(handler); + // Allocate and construct an operation to wrap the handler. - typedef signal_handler<Handler> op; + typedef signal_handler<Handler, IoExecutor> op; typename op::ptr p = { asio::detail::addressof(handler), op::ptr::allocate(handler), 0 }; - p.p = new (p.v) op(handler); + p.p = new (p.v) op(handler, io_ex); + + // Optionally register for per-operation cancellation. + if (slot.is_connected()) + { + p.p->cancellation_key_ = + &slot.template emplace<signal_op_cancellation>(this, &impl); + } - ASIO_HANDLER_CREATION((io_context_.context(), + ASIO_HANDLER_CREATION((scheduler_.context(), *p.p, "signal_set", &impl, 0, "async_wait")); start_wait_op(impl, p.p); @@ -179,20 +215,59 @@ private: // Helper function to start a wait operation. ASIO_DECL void start_wait_op(implementation_type& impl, signal_op* op); - // The io_context instance used for dispatching handlers. - io_context_impl& io_context_; + // Helper class used to implement per-operation cancellation + class signal_op_cancellation + { + public: + signal_op_cancellation(signal_set_service* s, implementation_type* i) + : service_(s), + implementation_(i) + { + } + + void operator()(cancellation_type_t type) + { + if (!!(type & + (cancellation_type::terminal + | cancellation_type::partial + | cancellation_type::total))) + { + service_->cancel_ops_by_key(*implementation_, this); + } + } + + private: + signal_set_service* service_; + implementation_type* implementation_; + }; + + // The scheduler used for dispatching handlers. +#if defined(ASIO_HAS_IOCP) + typedef class win_iocp_io_context scheduler_impl; +#else + typedef class scheduler scheduler_impl; +#endif + scheduler_impl& scheduler_; #if !defined(ASIO_WINDOWS) \ && !defined(ASIO_WINDOWS_RUNTIME) \ && !defined(__CYGWIN__) - // The type used for registering for pipe reactor notifications. + // The type used for processing pipe readiness notifications. class pipe_read_op; +# if defined(ASIO_HAS_IO_URING_AS_DEFAULT) + // The io_uring service used for waiting for pipe readiness. + io_uring_service& io_uring_service_; + + // The per I/O object data used for the pipe. + io_uring_service::per_io_object_data io_object_data_; +# else // defined(ASIO_HAS_IO_URING_AS_DEFAULT) // The reactor used for waiting for pipe readiness. reactor& reactor_; // The per-descriptor reactor data used for the pipe. reactor::per_descriptor_data reactor_data_; +# endif // defined(ASIO_HAS_IO_URING_AS_DEFAULT) #endif // !defined(ASIO_WINDOWS) // && !defined(ASIO_WINDOWS_RUNTIME) // && !defined(__CYGWIN__) |