summaryrefslogtreecommitdiffstatshomepage
path: root/3rdparty/asio/include/asio/detail/win_iocp_socket_accept_op.hpp
diff options
context:
space:
mode:
Diffstat (limited to '3rdparty/asio/include/asio/detail/win_iocp_socket_accept_op.hpp')
-rw-r--r--3rdparty/asio/include/asio/detail/win_iocp_socket_accept_op.hpp92
1 files changed, 67 insertions, 25 deletions
diff --git a/3rdparty/asio/include/asio/detail/win_iocp_socket_accept_op.hpp b/3rdparty/asio/include/asio/detail/win_iocp_socket_accept_op.hpp
index 937f4c0f6f3..f4aa850be80 100644
--- a/3rdparty/asio/include/asio/detail/win_iocp_socket_accept_op.hpp
+++ b/3rdparty/asio/include/asio/detail/win_iocp_socket_accept_op.hpp
@@ -2,7 +2,7 @@
// detail/win_iocp_socket_accept_op.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)
@@ -20,10 +20,9 @@
#if defined(ASIO_HAS_IOCP)
#include "asio/detail/bind_handler.hpp"
-#include "asio/detail/buffer_sequence_adapter.hpp"
#include "asio/detail/fenced_block.hpp"
#include "asio/detail/handler_alloc_helpers.hpp"
-#include "asio/detail/handler_invoke_helpers.hpp"
+#include "asio/detail/handler_work.hpp"
#include "asio/detail/memory.hpp"
#include "asio/detail/operation.hpp"
#include "asio/detail/socket_ops.hpp"
@@ -35,7 +34,8 @@
namespace asio {
namespace detail {
-template <typename Socket, typename Protocol, typename Handler>
+template <typename Socket, typename Protocol,
+ typename Handler, typename IoExecutor>
class win_iocp_socket_accept_op : public operation
{
public:
@@ -44,7 +44,7 @@ public:
win_iocp_socket_accept_op(win_iocp_socket_service_base& socket_service,
socket_type socket, Socket& peer, const Protocol& protocol,
typename Protocol::endpoint* peer_endpoint,
- bool enable_connection_aborted, Handler& handler)
+ bool enable_connection_aborted, Handler& handler, const IoExecutor& io_ex)
: operation(&win_iocp_socket_accept_op::do_complete),
socket_service_(socket_service),
socket_(socket),
@@ -52,9 +52,11 @@ public:
protocol_(protocol),
peer_endpoint_(peer_endpoint),
enable_connection_aborted_(enable_connection_aborted),
- handler_(ASIO_MOVE_CAST(Handler)(handler))
+ proxy_op_(0),
+ cancel_requested_(0),
+ handler_(static_cast<Handler&&>(handler)),
+ work_(handler_, io_ex)
{
- handler_work<Handler>::start(handler_);
}
socket_holder& new_socket()
@@ -72,6 +74,12 @@ public:
return sizeof(sockaddr_storage_type) + 16;
}
+ void enable_cancellation(long* cancel_requested, operation* proxy_op)
+ {
+ cancel_requested_ = cancel_requested;
+ proxy_op_ = proxy_op;
+ }
+
static void do_complete(void* owner, operation* base,
const asio::error_code& result_ec,
std::size_t /*bytes_transferred*/)
@@ -79,9 +87,9 @@ public:
asio::error_code ec(result_ec);
// Take ownership of the operation object.
+ ASIO_ASSUME(base != 0);
win_iocp_socket_accept_op* o(static_cast<win_iocp_socket_accept_op*>(base));
ptr p = { asio::detail::addressof(o->handler_), o, o };
- handler_work<Handler> w(o->handler_);
if (owner)
{
@@ -98,10 +106,13 @@ public:
&& !o->enable_connection_aborted_)
{
o->reset();
+ if (o->proxy_op_)
+ o->proxy_op_->reset();
o->socket_service_.restart_accept_op(o->socket_,
o->new_socket_, o->protocol_.family(),
o->protocol_.type(), o->protocol_.protocol(),
- o->output_buffer(), o->address_length(), o);
+ o->output_buffer(), o->address_length(),
+ o->cancel_requested_, o->proxy_op_ ? o->proxy_op_ : o);
p.v = p.p = 0;
return;
}
@@ -124,6 +135,13 @@ public:
ASIO_HANDLER_COMPLETION((*o));
+ // Take ownership of the operation's outstanding work.
+ handler_work<Handler, IoExecutor> w(
+ static_cast<handler_work<Handler, IoExecutor>&&>(
+ o->work_));
+
+ ASIO_ERROR_LOCATION(ec);
+
// Make a copy of the handler so that the memory can be deallocated before
// the upcall is made. Even if we're not about to make an upcall, a
// sub-object of the handler may be the true owner of the memory associated
@@ -154,12 +172,14 @@ private:
typename Protocol::endpoint* peer_endpoint_;
unsigned char output_buffer_[(sizeof(sockaddr_storage_type) + 16) * 2];
bool enable_connection_aborted_;
+ operation* proxy_op_;
+ long* cancel_requested_;
Handler handler_;
+ handler_work<Handler, IoExecutor> work_;
};
-#if defined(ASIO_HAS_MOVE)
-
-template <typename Protocol, typename Handler>
+template <typename Protocol, typename PeerIoExecutor,
+ typename Handler, typename IoExecutor>
class win_iocp_socket_move_accept_op : public operation
{
public:
@@ -167,19 +187,21 @@ public:
win_iocp_socket_move_accept_op(
win_iocp_socket_service_base& socket_service, socket_type socket,
- const Protocol& protocol, asio::io_context& peer_io_context,
+ const Protocol& protocol, const PeerIoExecutor& peer_io_ex,
typename Protocol::endpoint* peer_endpoint,
- bool enable_connection_aborted, Handler& handler)
+ bool enable_connection_aborted, Handler& handler, const IoExecutor& io_ex)
: operation(&win_iocp_socket_move_accept_op::do_complete),
socket_service_(socket_service),
socket_(socket),
- peer_(peer_io_context),
+ peer_(peer_io_ex),
protocol_(protocol),
peer_endpoint_(peer_endpoint),
enable_connection_aborted_(enable_connection_aborted),
- handler_(ASIO_MOVE_CAST(Handler)(handler))
+ cancel_requested_(0),
+ proxy_op_(0),
+ handler_(static_cast<Handler&&>(handler)),
+ work_(handler_, io_ex)
{
- handler_work<Handler>::start(handler_);
}
socket_holder& new_socket()
@@ -197,6 +219,12 @@ public:
return sizeof(sockaddr_storage_type) + 16;
}
+ void enable_cancellation(long* cancel_requested, operation* proxy_op)
+ {
+ cancel_requested_ = cancel_requested;
+ proxy_op_ = proxy_op;
+ }
+
static void do_complete(void* owner, operation* base,
const asio::error_code& result_ec,
std::size_t /*bytes_transferred*/)
@@ -204,10 +232,10 @@ public:
asio::error_code ec(result_ec);
// Take ownership of the operation object.
+ ASIO_ASSUME(base != 0);
win_iocp_socket_move_accept_op* o(
static_cast<win_iocp_socket_move_accept_op*>(base));
ptr p = { asio::detail::addressof(o->handler_), o, o };
- handler_work<Handler> w(o->handler_);
if (owner)
{
@@ -224,10 +252,13 @@ public:
&& !o->enable_connection_aborted_)
{
o->reset();
+ if (o->proxy_op_)
+ o->proxy_op_->reset();
o->socket_service_.restart_accept_op(o->socket_,
o->new_socket_, o->protocol_.family(),
o->protocol_.type(), o->protocol_.protocol(),
- o->output_buffer(), o->address_length(), o);
+ o->output_buffer(), o->address_length(),
+ o->cancel_requested_, o->proxy_op_ ? o->proxy_op_ : o);
p.v = p.p = 0;
return;
}
@@ -250,6 +281,13 @@ public:
ASIO_HANDLER_COMPLETION((*o));
+ // Take ownership of the operation's outstanding work.
+ handler_work<Handler, IoExecutor> w(
+ static_cast<handler_work<Handler, IoExecutor>&&>(
+ o->work_));
+
+ ASIO_ERROR_LOCATION(ec);
+
// Make a copy of the handler so that the memory can be deallocated before
// the upcall is made. Even if we're not about to make an upcall, a
// sub-object of the handler may be the true owner of the memory associated
@@ -257,9 +295,9 @@ public:
// to ensure that any owning sub-object remains valid until after we have
// deallocated the memory here.
detail::move_binder2<Handler,
- asio::error_code, typename Protocol::socket>
- handler(0, ASIO_MOVE_CAST(Handler)(o->handler_), ec,
- ASIO_MOVE_CAST(typename Protocol::socket)(o->peer_));
+ asio::error_code, peer_socket_type>
+ handler(0, static_cast<Handler&&>(o->handler_), ec,
+ static_cast<peer_socket_type&&>(o->peer_));
p.h = asio::detail::addressof(handler.handler_);
p.reset();
@@ -274,19 +312,23 @@ public:
}
private:
+ typedef typename Protocol::socket::template
+ rebind_executor<PeerIoExecutor>::other peer_socket_type;
+
win_iocp_socket_service_base& socket_service_;
socket_type socket_;
socket_holder new_socket_;
- typename Protocol::socket peer_;
+ peer_socket_type peer_;
Protocol protocol_;
typename Protocol::endpoint* peer_endpoint_;
unsigned char output_buffer_[(sizeof(sockaddr_storage_type) + 16) * 2];
bool enable_connection_aborted_;
+ long* cancel_requested_;
+ operation* proxy_op_;
Handler handler_;
+ handler_work<Handler, IoExecutor> work_;
};
-#endif // defined(ASIO_HAS_MOVE)
-
} // namespace detail
} // namespace asio