11 #ifndef ASIO_DETAIL_REACTIVE_SOCKET_ACCEPT_OP_HPP 12 #define ASIO_DETAIL_REACTIVE_SOCKET_ACCEPT_OP_HPP 14 #if defined(_MSC_VER) && (_MSC_VER >= 1200) 16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) 18 #include "asio/detail/config.hpp" 19 #include "asio/detail/bind_handler.hpp" 20 #include "asio/detail/fenced_block.hpp" 21 #include "asio/detail/handler_alloc_helpers.hpp" 22 #include "asio/detail/handler_invoke_helpers.hpp" 23 #include "asio/detail/handler_work.hpp" 24 #include "asio/detail/memory.hpp" 25 #include "asio/detail/reactor_op.hpp" 26 #include "asio/detail/socket_holder.hpp" 27 #include "asio/detail/socket_ops.hpp" 29 #include "asio/detail/push_options.hpp" 34 template <
typename Socket,
typename Protocol>
39 socket_type socket, socket_ops::state_type state, Socket& peer,
40 const Protocol& protocol,
typename Protocol::endpoint* peer_endpoint,
41 func_type complete_func)
43 &reactive_socket_accept_op_base::do_perform, complete_func),
48 peer_endpoint_(peer_endpoint),
49 addrlen_(peer_endpoint ? peer_endpoint->capacity() : 0)
56 static_cast<reactive_socket_accept_op_base*>(base));
58 socket_type new_socket = invalid_socket;
59 status result = socket_ops::non_blocking_accept(o->socket_,
60 o->state_, o->peer_endpoint_ ? o->peer_endpoint_->data() : 0,
61 o->peer_endpoint_ ? &o->addrlen_ : 0, o->ec_, new_socket)
63 o->new_socket_.reset(new_socket);
65 ASIO_HANDLER_REACTOR_OPERATION((*o,
"non_blocking_accept", o->ec_));
72 if (new_socket_.get() != invalid_socket)
75 peer_endpoint_->resize(addrlen_);
76 peer_.assign(protocol_, new_socket_.get(), ec_);
78 new_socket_.release();
84 socket_ops::state_type state_;
88 typename Protocol::endpoint* peer_endpoint_;
92 template <
typename Socket,
typename Protocol,
93 typename Handler,
typename IoExecutor>
101 socket_type socket, socket_ops::state_type state, Socket& peer,
102 const Protocol& protocol,
typename Protocol::endpoint* peer_endpoint,
103 Handler& handler,
const IoExecutor& io_ex)
105 success_ec, socket, state, peer, protocol, peer_endpoint,
106 &reactive_socket_accept_op::do_complete),
107 handler_(ASIO_MOVE_CAST(Handler)(handler)),
108 work_(handler_, io_ex)
112 static void do_complete(
void* owner, operation* base,
118 ptr p = { asio::detail::addressof(o->handler_), o, o };
124 ASIO_HANDLER_COMPLETION((*o));
138 handler(o->handler_, o->ec_);
139 p.h = asio::detail::addressof(handler.handler_);
146 ASIO_HANDLER_INVOCATION_BEGIN((handler.arg1_));
147 w.complete(handler, handler.handler_);
148 ASIO_HANDLER_INVOCATION_END;
157 #if defined(ASIO_HAS_MOVE) 159 template <
typename Protocol,
typename PeerIoExecutor,
160 typename Handler,
typename IoExecutor>
161 class reactive_socket_move_accept_op :
162 private Protocol::socket::template rebind_executor<PeerIoExecutor>::other,
164 typename Protocol::socket::template rebind_executor<PeerIoExecutor>::other,
168 ASIO_DEFINE_HANDLER_PTR(reactive_socket_move_accept_op);
171 const PeerIoExecutor& peer_io_ex, socket_type socket,
172 socket_ops::state_type state,
const Protocol& protocol,
173 typename Protocol::endpoint* peer_endpoint, Handler& handler,
174 const IoExecutor& io_ex)
175 : peer_socket_type(peer_io_ex),
177 success_ec, socket, state, *
this, protocol, peer_endpoint,
178 &reactive_socket_move_accept_op::do_complete),
179 handler_(ASIO_MOVE_CAST(Handler)(handler)),
180 work_(handler_, io_ex)
184 static void do_complete(
void* owner, operation* base,
189 reactive_socket_move_accept_op* o(
190 static_cast<reactive_socket_move_accept_op*>(base));
191 ptr p = { asio::detail::addressof(o->handler_), o, o };
197 ASIO_HANDLER_COMPLETION((*o));
210 detail::move_binder2<Handler,
212 handler(0, ASIO_MOVE_CAST(Handler)(o->handler_), o->ec_,
213 ASIO_MOVE_CAST(peer_socket_type)(*o));
214 p.h = asio::detail::addressof(handler.handler_);
221 ASIO_HANDLER_INVOCATION_BEGIN((handler.arg1_,
"..."));
222 w.complete(handler, handler.handler_);
223 ASIO_HANDLER_INVOCATION_END;
228 typedef typename Protocol::socket::template
229 rebind_executor<PeerIoExecutor>::other peer_socket_type;
235 #endif // defined(ASIO_HAS_MOVE) 240 #include "asio/detail/pop_options.hpp" 242 #endif // ASIO_DETAIL_REACTIVE_SOCKET_ACCEPT_OP_HPP Definition: bind_handler.hpp:32
Definition: null_fenced_block.hpp:25
Class to represent an error code value.
Definition: error_code.hpp:80
Definition: reactive_socket_accept_op.hpp:35
Definition: socket_holder.hpp:28
Definition: reactive_socket_accept_op.hpp:94
Definition: reactor_op.hpp:26
Definition: any_io_executor.hpp:28