// detail/reactive_socket_service.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
-// Copyright (c) 2003-2020 Christopher M. Kohlhoff (chris at kohlhoff dot com)
+// Copyright (c) 2003-2022 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)
#include <boost/asio/detail/config.hpp>
-#if !defined(BOOST_ASIO_HAS_IOCP)
+#if !defined(BOOST_ASIO_HAS_IOCP) \
+ && !defined(BOOST_ASIO_HAS_IO_URING_AS_DEFAULT)
#include <boost/asio/buffer.hpp>
#include <boost/asio/error.hpp>
bool is_continuation =
boost_asio_handler_cont_helpers::is_continuation(handler);
+ typename associated_cancellation_slot<Handler>::type slot
+ = boost::asio::get_associated_cancellation_slot(handler);
+
// Allocate and construct an operation to wrap the handler.
typedef reactive_socket_sendto_op<ConstBufferSequence,
endpoint_type, Handler, IoExecutor> op;
p.p = new (p.v) op(success_ec_, impl.socket_,
buffers, destination, flags, handler, io_ex);
+ // Optionally register for per-operation cancellation.
+ if (slot.is_connected())
+ {
+ p.p->cancellation_key_ =
+ &slot.template emplace<reactor_op_cancellation>(
+ &reactor_, &impl.reactor_data_, impl.socket_, reactor::write_op);
+ }
+
BOOST_ASIO_HANDLER_CREATION((reactor_.context(), *p.p, "socket",
&impl, impl.socket_, "async_send_to"));
bool is_continuation =
boost_asio_handler_cont_helpers::is_continuation(handler);
+ typename associated_cancellation_slot<Handler>::type slot
+ = boost::asio::get_associated_cancellation_slot(handler);
+
// Allocate and construct an operation to wrap the handler.
typedef reactive_null_buffers_op<Handler, IoExecutor> op;
typename op::ptr p = { boost::asio::detail::addressof(handler),
op::ptr::allocate(handler), 0 };
p.p = new (p.v) op(success_ec_, handler, io_ex);
+ // Optionally register for per-operation cancellation.
+ if (slot.is_connected())
+ {
+ p.p->cancellation_key_ =
+ &slot.template emplace<reactor_op_cancellation>(
+ &reactor_, &impl.reactor_data_, impl.socket_, reactor::write_op);
+ }
+
BOOST_ASIO_HANDLER_CREATION((reactor_.context(), *p.p, "socket",
&impl, impl.socket_, "async_send_to(null_buffers)"));
bool is_continuation =
boost_asio_handler_cont_helpers::is_continuation(handler);
+ typename associated_cancellation_slot<Handler>::type slot
+ = boost::asio::get_associated_cancellation_slot(handler);
+
// Allocate and construct an operation to wrap the handler.
typedef reactive_socket_recvfrom_op<MutableBufferSequence,
endpoint_type, Handler, IoExecutor> op;
p.p = new (p.v) op(success_ec_, impl.socket_, protocol,
buffers, sender_endpoint, flags, handler, io_ex);
+ // Optionally register for per-operation cancellation.
+ if (slot.is_connected())
+ {
+ p.p->cancellation_key_ =
+ &slot.template emplace<reactor_op_cancellation>(
+ &reactor_, &impl.reactor_data_, impl.socket_, reactor::read_op);
+ }
+
BOOST_ASIO_HANDLER_CREATION((reactor_.context(), *p.p, "socket",
&impl, impl.socket_, "async_receive_from"));
bool is_continuation =
boost_asio_handler_cont_helpers::is_continuation(handler);
+ typename associated_cancellation_slot<Handler>::type slot
+ = boost::asio::get_associated_cancellation_slot(handler);
+
// Allocate and construct an operation to wrap the handler.
typedef reactive_null_buffers_op<Handler, IoExecutor> op;
typename op::ptr p = { boost::asio::detail::addressof(handler),
op::ptr::allocate(handler), 0 };
p.p = new (p.v) op(success_ec_, handler, io_ex);
+ // Optionally register for per-operation cancellation.
+ if (slot.is_connected())
+ {
+ p.p->cancellation_key_ =
+ &slot.template emplace<reactor_op_cancellation>(
+ &reactor_, &impl.reactor_data_, impl.socket_, reactor::read_op);
+ }
+
BOOST_ASIO_HANDLER_CREATION((reactor_.context(), *p.p, "socket",
&impl, impl.socket_, "async_receive_from(null_buffers)"));
bool is_continuation =
boost_asio_handler_cont_helpers::is_continuation(handler);
+ typename associated_cancellation_slot<Handler>::type slot
+ = boost::asio::get_associated_cancellation_slot(handler);
+
// Allocate and construct an operation to wrap the handler.
typedef reactive_socket_accept_op<Socket, Protocol, Handler, IoExecutor> op;
typename op::ptr p = { boost::asio::detail::addressof(handler),
p.p = new (p.v) op(success_ec_, impl.socket_, impl.state_,
peer, impl.protocol_, peer_endpoint, handler, io_ex);
+ // Optionally register for per-operation cancellation.
+ if (slot.is_connected() && !peer.is_open())
+ {
+ p.p->cancellation_key_ =
+ &slot.template emplace<reactor_op_cancellation>(
+ &reactor_, &impl.reactor_data_, impl.socket_, reactor::read_op);
+ }
+
BOOST_ASIO_HANDLER_CREATION((reactor_.context(), *p.p, "socket",
&impl, impl.socket_, "async_accept"));
bool is_continuation =
boost_asio_handler_cont_helpers::is_continuation(handler);
+ typename associated_cancellation_slot<Handler>::type slot
+ = boost::asio::get_associated_cancellation_slot(handler);
+
// Allocate and construct an operation to wrap the handler.
typedef reactive_socket_move_accept_op<Protocol,
PeerIoExecutor, Handler, IoExecutor> op;
p.p = new (p.v) op(success_ec_, peer_io_ex, impl.socket_,
impl.state_, impl.protocol_, peer_endpoint, handler, io_ex);
+ // Optionally register for per-operation cancellation.
+ if (slot.is_connected())
+ {
+ p.p->cancellation_key_ =
+ &slot.template emplace<reactor_op_cancellation>(
+ &reactor_, &impl.reactor_data_, impl.socket_, reactor::read_op);
+ }
+
BOOST_ASIO_HANDLER_CREATION((reactor_.context(), *p.p, "socket",
&impl, impl.socket_, "async_accept"));
bool is_continuation =
boost_asio_handler_cont_helpers::is_continuation(handler);
+ typename associated_cancellation_slot<Handler>::type slot
+ = boost::asio::get_associated_cancellation_slot(handler);
+
// Allocate and construct an operation to wrap the handler.
typedef reactive_socket_connect_op<Handler, IoExecutor> op;
typename op::ptr p = { boost::asio::detail::addressof(handler),
op::ptr::allocate(handler), 0 };
p.p = new (p.v) op(success_ec_, impl.socket_, handler, io_ex);
+ // Optionally register for per-operation cancellation.
+ if (slot.is_connected())
+ {
+ p.p->cancellation_key_ =
+ &slot.template emplace<reactor_op_cancellation>(
+ &reactor_, &impl.reactor_data_, impl.socket_, reactor::connect_op);
+ }
+
BOOST_ASIO_HANDLER_CREATION((reactor_.context(), *p.p, "socket",
&impl, impl.socket_, "async_connect"));
#include <boost/asio/detail/pop_options.hpp>
#endif // !defined(BOOST_ASIO_HAS_IOCP)
+ // && !defined(BOOST_ASIO_HAS_IO_URING_AS_DEFAULT)
#endif // BOOST_ASIO_DETAIL_REACTIVE_SOCKET_SERVICE_HPP