win_iocp_socket_service.hpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601
  1. //
  2. // detail/win_iocp_socket_service.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2018 Christopher M. Kohlhoff (chris at kohlhoff dot com)
  6. //
  7. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  8. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  9. //
  10. #ifndef BOOST_ASIO_DETAIL_WIN_IOCP_SOCKET_SERVICE_HPP
  11. #define BOOST_ASIO_DETAIL_WIN_IOCP_SOCKET_SERVICE_HPP
  12. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  13. # pragma once
  14. #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
  15. #include <boost/asio/detail/config.hpp>
  16. #if defined(BOOST_ASIO_HAS_IOCP)
  17. #include <cstring>
  18. #include <boost/asio/error.hpp>
  19. #include <boost/asio/io_context.hpp>
  20. #include <boost/asio/socket_base.hpp>
  21. #include <boost/asio/detail/bind_handler.hpp>
  22. #include <boost/asio/detail/buffer_sequence_adapter.hpp>
  23. #include <boost/asio/detail/fenced_block.hpp>
  24. #include <boost/asio/detail/handler_alloc_helpers.hpp>
  25. #include <boost/asio/detail/handler_invoke_helpers.hpp>
  26. #include <boost/asio/detail/memory.hpp>
  27. #include <boost/asio/detail/mutex.hpp>
  28. #include <boost/asio/detail/operation.hpp>
  29. #include <boost/asio/detail/reactor_op.hpp>
  30. #include <boost/asio/detail/select_reactor.hpp>
  31. #include <boost/asio/detail/socket_holder.hpp>
  32. #include <boost/asio/detail/socket_ops.hpp>
  33. #include <boost/asio/detail/socket_types.hpp>
  34. #include <boost/asio/detail/win_iocp_io_context.hpp>
  35. #include <boost/asio/detail/win_iocp_null_buffers_op.hpp>
  36. #include <boost/asio/detail/win_iocp_socket_accept_op.hpp>
  37. #include <boost/asio/detail/win_iocp_socket_connect_op.hpp>
  38. #include <boost/asio/detail/win_iocp_socket_recvfrom_op.hpp>
  39. #include <boost/asio/detail/win_iocp_socket_send_op.hpp>
  40. #include <boost/asio/detail/win_iocp_socket_service_base.hpp>
  41. #include <boost/asio/detail/push_options.hpp>
  42. namespace boost {
  43. namespace asio {
  44. namespace detail {
  45. template <typename Protocol>
  46. class win_iocp_socket_service :
  47. public service_base<win_iocp_socket_service<Protocol> >,
  48. public win_iocp_socket_service_base
  49. {
  50. public:
  51. // The protocol type.
  52. typedef Protocol protocol_type;
  53. // The endpoint type.
  54. typedef typename Protocol::endpoint endpoint_type;
  55. // The native type of a socket.
  56. class native_handle_type
  57. {
  58. public:
  59. native_handle_type(socket_type s)
  60. : socket_(s),
  61. have_remote_endpoint_(false)
  62. {
  63. }
  64. native_handle_type(socket_type s, const endpoint_type& ep)
  65. : socket_(s),
  66. have_remote_endpoint_(true),
  67. remote_endpoint_(ep)
  68. {
  69. }
  70. void operator=(socket_type s)
  71. {
  72. socket_ = s;
  73. have_remote_endpoint_ = false;
  74. remote_endpoint_ = endpoint_type();
  75. }
  76. operator socket_type() const
  77. {
  78. return socket_;
  79. }
  80. bool have_remote_endpoint() const
  81. {
  82. return have_remote_endpoint_;
  83. }
  84. endpoint_type remote_endpoint() const
  85. {
  86. return remote_endpoint_;
  87. }
  88. private:
  89. socket_type socket_;
  90. bool have_remote_endpoint_;
  91. endpoint_type remote_endpoint_;
  92. };
  93. // The implementation type of the socket.
  94. struct implementation_type :
  95. win_iocp_socket_service_base::base_implementation_type
  96. {
  97. // Default constructor.
  98. implementation_type()
  99. : protocol_(endpoint_type().protocol()),
  100. have_remote_endpoint_(false),
  101. remote_endpoint_()
  102. {
  103. }
  104. // The protocol associated with the socket.
  105. protocol_type protocol_;
  106. // Whether we have a cached remote endpoint.
  107. bool have_remote_endpoint_;
  108. // A cached remote endpoint.
  109. endpoint_type remote_endpoint_;
  110. };
  111. // Constructor.
  112. win_iocp_socket_service(boost::asio::io_context& io_context)
  113. : service_base<win_iocp_socket_service<Protocol> >(io_context),
  114. win_iocp_socket_service_base(io_context)
  115. {
  116. }
  117. // Destroy all user-defined handler objects owned by the service.
  118. void shutdown()
  119. {
  120. this->base_shutdown();
  121. }
  122. // Move-construct a new socket implementation.
  123. void move_construct(implementation_type& impl,
  124. implementation_type& other_impl)
  125. {
  126. this->base_move_construct(impl, other_impl);
  127. impl.protocol_ = other_impl.protocol_;
  128. other_impl.protocol_ = endpoint_type().protocol();
  129. impl.have_remote_endpoint_ = other_impl.have_remote_endpoint_;
  130. other_impl.have_remote_endpoint_ = false;
  131. impl.remote_endpoint_ = other_impl.remote_endpoint_;
  132. other_impl.remote_endpoint_ = endpoint_type();
  133. }
  134. // Move-assign from another socket implementation.
  135. void move_assign(implementation_type& impl,
  136. win_iocp_socket_service_base& other_service,
  137. implementation_type& other_impl)
  138. {
  139. this->base_move_assign(impl, other_service, other_impl);
  140. impl.protocol_ = other_impl.protocol_;
  141. other_impl.protocol_ = endpoint_type().protocol();
  142. impl.have_remote_endpoint_ = other_impl.have_remote_endpoint_;
  143. other_impl.have_remote_endpoint_ = false;
  144. impl.remote_endpoint_ = other_impl.remote_endpoint_;
  145. other_impl.remote_endpoint_ = endpoint_type();
  146. }
  147. // Move-construct a new socket implementation from another protocol type.
  148. template <typename Protocol1>
  149. void converting_move_construct(implementation_type& impl,
  150. win_iocp_socket_service<Protocol1>&,
  151. typename win_iocp_socket_service<
  152. Protocol1>::implementation_type& other_impl)
  153. {
  154. this->base_move_construct(impl, other_impl);
  155. impl.protocol_ = protocol_type(other_impl.protocol_);
  156. other_impl.protocol_ = typename Protocol1::endpoint().protocol();
  157. impl.have_remote_endpoint_ = other_impl.have_remote_endpoint_;
  158. other_impl.have_remote_endpoint_ = false;
  159. impl.remote_endpoint_ = other_impl.remote_endpoint_;
  160. other_impl.remote_endpoint_ = typename Protocol1::endpoint();
  161. }
  162. // Open a new socket implementation.
  163. boost::system::error_code open(implementation_type& impl,
  164. const protocol_type& protocol, boost::system::error_code& ec)
  165. {
  166. if (!do_open(impl, protocol.family(),
  167. protocol.type(), protocol.protocol(), ec))
  168. {
  169. impl.protocol_ = protocol;
  170. impl.have_remote_endpoint_ = false;
  171. impl.remote_endpoint_ = endpoint_type();
  172. }
  173. return ec;
  174. }
  175. // Assign a native socket to a socket implementation.
  176. boost::system::error_code assign(implementation_type& impl,
  177. const protocol_type& protocol, const native_handle_type& native_socket,
  178. boost::system::error_code& ec)
  179. {
  180. if (!do_assign(impl, protocol.type(), native_socket, ec))
  181. {
  182. impl.protocol_ = protocol;
  183. impl.have_remote_endpoint_ = native_socket.have_remote_endpoint();
  184. impl.remote_endpoint_ = native_socket.remote_endpoint();
  185. }
  186. return ec;
  187. }
  188. // Get the native socket representation.
  189. native_handle_type native_handle(implementation_type& impl)
  190. {
  191. if (impl.have_remote_endpoint_)
  192. return native_handle_type(impl.socket_, impl.remote_endpoint_);
  193. return native_handle_type(impl.socket_);
  194. }
  195. // Bind the socket to the specified local endpoint.
  196. boost::system::error_code bind(implementation_type& impl,
  197. const endpoint_type& endpoint, boost::system::error_code& ec)
  198. {
  199. socket_ops::bind(impl.socket_, endpoint.data(), endpoint.size(), ec);
  200. return ec;
  201. }
  202. // Set a socket option.
  203. template <typename Option>
  204. boost::system::error_code set_option(implementation_type& impl,
  205. const Option& option, boost::system::error_code& ec)
  206. {
  207. socket_ops::setsockopt(impl.socket_, impl.state_,
  208. option.level(impl.protocol_), option.name(impl.protocol_),
  209. option.data(impl.protocol_), option.size(impl.protocol_), ec);
  210. return ec;
  211. }
  212. // Set a socket option.
  213. template <typename Option>
  214. boost::system::error_code get_option(const implementation_type& impl,
  215. Option& option, boost::system::error_code& ec) const
  216. {
  217. std::size_t size = option.size(impl.protocol_);
  218. socket_ops::getsockopt(impl.socket_, impl.state_,
  219. option.level(impl.protocol_), option.name(impl.protocol_),
  220. option.data(impl.protocol_), &size, ec);
  221. if (!ec)
  222. option.resize(impl.protocol_, size);
  223. return ec;
  224. }
  225. // Get the local endpoint.
  226. endpoint_type local_endpoint(const implementation_type& impl,
  227. boost::system::error_code& ec) const
  228. {
  229. endpoint_type endpoint;
  230. std::size_t addr_len = endpoint.capacity();
  231. if (socket_ops::getsockname(impl.socket_, endpoint.data(), &addr_len, ec))
  232. return endpoint_type();
  233. endpoint.resize(addr_len);
  234. return endpoint;
  235. }
  236. // Get the remote endpoint.
  237. endpoint_type remote_endpoint(const implementation_type& impl,
  238. boost::system::error_code& ec) const
  239. {
  240. endpoint_type endpoint = impl.remote_endpoint_;
  241. std::size_t addr_len = endpoint.capacity();
  242. if (socket_ops::getpeername(impl.socket_, endpoint.data(),
  243. &addr_len, impl.have_remote_endpoint_, ec))
  244. return endpoint_type();
  245. endpoint.resize(addr_len);
  246. return endpoint;
  247. }
  248. // Disable sends or receives on the socket.
  249. boost::system::error_code shutdown(base_implementation_type& impl,
  250. socket_base::shutdown_type what, boost::system::error_code& ec)
  251. {
  252. socket_ops::shutdown(impl.socket_, what, ec);
  253. return ec;
  254. }
  255. // Send a datagram to the specified endpoint. Returns the number of bytes
  256. // sent.
  257. template <typename ConstBufferSequence>
  258. size_t send_to(implementation_type& impl, const ConstBufferSequence& buffers,
  259. const endpoint_type& destination, socket_base::message_flags flags,
  260. boost::system::error_code& ec)
  261. {
  262. buffer_sequence_adapter<boost::asio::const_buffer,
  263. ConstBufferSequence> bufs(buffers);
  264. return socket_ops::sync_sendto(impl.socket_, impl.state_,
  265. bufs.buffers(), bufs.count(), flags,
  266. destination.data(), destination.size(), ec);
  267. }
  268. // Wait until data can be sent without blocking.
  269. size_t send_to(implementation_type& impl, const null_buffers&,
  270. const endpoint_type&, socket_base::message_flags,
  271. boost::system::error_code& ec)
  272. {
  273. // Wait for socket to become ready.
  274. socket_ops::poll_write(impl.socket_, impl.state_, -1, ec);
  275. return 0;
  276. }
  277. // Start an asynchronous send. The data being sent must be valid for the
  278. // lifetime of the asynchronous operation.
  279. template <typename ConstBufferSequence, typename Handler>
  280. void async_send_to(implementation_type& impl,
  281. const ConstBufferSequence& buffers, const endpoint_type& destination,
  282. socket_base::message_flags flags, Handler& handler)
  283. {
  284. // Allocate and construct an operation to wrap the handler.
  285. typedef win_iocp_socket_send_op<ConstBufferSequence, Handler> op;
  286. typename op::ptr p = { boost::asio::detail::addressof(handler),
  287. op::ptr::allocate(handler), 0 };
  288. p.p = new (p.v) op(impl.cancel_token_, buffers, handler);
  289. BOOST_ASIO_HANDLER_CREATION((io_context_, *p.p, "socket",
  290. &impl, impl.socket_, "async_send_to"));
  291. buffer_sequence_adapter<boost::asio::const_buffer,
  292. ConstBufferSequence> bufs(buffers);
  293. start_send_to_op(impl, bufs.buffers(), bufs.count(),
  294. destination.data(), static_cast<int>(destination.size()),
  295. flags, p.p);
  296. p.v = p.p = 0;
  297. }
  298. // Start an asynchronous wait until data can be sent without blocking.
  299. template <typename Handler>
  300. void async_send_to(implementation_type& impl, const null_buffers&,
  301. const endpoint_type&, socket_base::message_flags, Handler& handler)
  302. {
  303. // Allocate and construct an operation to wrap the handler.
  304. typedef win_iocp_null_buffers_op<Handler> op;
  305. typename op::ptr p = { boost::asio::detail::addressof(handler),
  306. op::ptr::allocate(handler), 0 };
  307. p.p = new (p.v) op(impl.cancel_token_, handler);
  308. BOOST_ASIO_HANDLER_CREATION((io_context_, *p.p, "socket",
  309. &impl, impl.socket_, "async_send_to(null_buffers)"));
  310. start_reactor_op(impl, select_reactor::write_op, p.p);
  311. p.v = p.p = 0;
  312. }
  313. // Receive a datagram with the endpoint of the sender. Returns the number of
  314. // bytes received.
  315. template <typename MutableBufferSequence>
  316. size_t receive_from(implementation_type& impl,
  317. const MutableBufferSequence& buffers,
  318. endpoint_type& sender_endpoint, socket_base::message_flags flags,
  319. boost::system::error_code& ec)
  320. {
  321. buffer_sequence_adapter<boost::asio::mutable_buffer,
  322. MutableBufferSequence> bufs(buffers);
  323. std::size_t addr_len = sender_endpoint.capacity();
  324. std::size_t bytes_recvd = socket_ops::sync_recvfrom(
  325. impl.socket_, impl.state_, bufs.buffers(), bufs.count(),
  326. flags, sender_endpoint.data(), &addr_len, ec);
  327. if (!ec)
  328. sender_endpoint.resize(addr_len);
  329. return bytes_recvd;
  330. }
  331. // Wait until data can be received without blocking.
  332. size_t receive_from(implementation_type& impl,
  333. const null_buffers&, endpoint_type& sender_endpoint,
  334. socket_base::message_flags, boost::system::error_code& ec)
  335. {
  336. // Wait for socket to become ready.
  337. socket_ops::poll_read(impl.socket_, impl.state_, -1, ec);
  338. // Reset endpoint since it can be given no sensible value at this time.
  339. sender_endpoint = endpoint_type();
  340. return 0;
  341. }
  342. // Start an asynchronous receive. The buffer for the data being received and
  343. // the sender_endpoint object must both be valid for the lifetime of the
  344. // asynchronous operation.
  345. template <typename MutableBufferSequence, typename Handler>
  346. void async_receive_from(implementation_type& impl,
  347. const MutableBufferSequence& buffers, endpoint_type& sender_endp,
  348. socket_base::message_flags flags, Handler& handler)
  349. {
  350. // Allocate and construct an operation to wrap the handler.
  351. typedef win_iocp_socket_recvfrom_op<
  352. MutableBufferSequence, endpoint_type, Handler> op;
  353. typename op::ptr p = { boost::asio::detail::addressof(handler),
  354. op::ptr::allocate(handler), 0 };
  355. p.p = new (p.v) op(sender_endp, impl.cancel_token_, buffers, handler);
  356. BOOST_ASIO_HANDLER_CREATION((io_context_, *p.p, "socket",
  357. &impl, impl.socket_, "async_receive_from"));
  358. buffer_sequence_adapter<boost::asio::mutable_buffer,
  359. MutableBufferSequence> bufs(buffers);
  360. start_receive_from_op(impl, bufs.buffers(), bufs.count(),
  361. sender_endp.data(), flags, &p.p->endpoint_size(), p.p);
  362. p.v = p.p = 0;
  363. }
  364. // Wait until data can be received without blocking.
  365. template <typename Handler>
  366. void async_receive_from(implementation_type& impl,
  367. const null_buffers&, endpoint_type& sender_endpoint,
  368. socket_base::message_flags flags, Handler& handler)
  369. {
  370. // Allocate and construct an operation to wrap the handler.
  371. typedef win_iocp_null_buffers_op<Handler> op;
  372. typename op::ptr p = { boost::asio::detail::addressof(handler),
  373. op::ptr::allocate(handler), 0 };
  374. p.p = new (p.v) op(impl.cancel_token_, handler);
  375. BOOST_ASIO_HANDLER_CREATION((io_context_, *p.p, "socket",
  376. &impl, impl.socket_, "async_receive_from(null_buffers)"));
  377. // Reset endpoint since it can be given no sensible value at this time.
  378. sender_endpoint = endpoint_type();
  379. start_null_buffers_receive_op(impl, flags, p.p);
  380. p.v = p.p = 0;
  381. }
  382. // Accept a new connection.
  383. template <typename Socket>
  384. boost::system::error_code accept(implementation_type& impl, Socket& peer,
  385. endpoint_type* peer_endpoint, boost::system::error_code& ec)
  386. {
  387. // We cannot accept a socket that is already open.
  388. if (peer.is_open())
  389. {
  390. ec = boost::asio::error::already_open;
  391. return ec;
  392. }
  393. std::size_t addr_len = peer_endpoint ? peer_endpoint->capacity() : 0;
  394. socket_holder new_socket(socket_ops::sync_accept(impl.socket_,
  395. impl.state_, peer_endpoint ? peer_endpoint->data() : 0,
  396. peer_endpoint ? &addr_len : 0, ec));
  397. // On success, assign new connection to peer socket object.
  398. if (new_socket.get() != invalid_socket)
  399. {
  400. if (peer_endpoint)
  401. peer_endpoint->resize(addr_len);
  402. peer.assign(impl.protocol_, new_socket.get(), ec);
  403. if (!ec)
  404. new_socket.release();
  405. }
  406. return ec;
  407. }
  408. #if defined(BOOST_ASIO_HAS_MOVE)
  409. // Accept a new connection.
  410. typename Protocol::socket accept(implementation_type& impl,
  411. io_context* peer_io_context, endpoint_type* peer_endpoint,
  412. boost::system::error_code& ec)
  413. {
  414. typename Protocol::socket peer(
  415. peer_io_context ? *peer_io_context : io_context_);
  416. std::size_t addr_len = peer_endpoint ? peer_endpoint->capacity() : 0;
  417. socket_holder new_socket(socket_ops::sync_accept(impl.socket_,
  418. impl.state_, peer_endpoint ? peer_endpoint->data() : 0,
  419. peer_endpoint ? &addr_len : 0, ec));
  420. // On success, assign new connection to peer socket object.
  421. if (new_socket.get() != invalid_socket)
  422. {
  423. if (peer_endpoint)
  424. peer_endpoint->resize(addr_len);
  425. peer.assign(impl.protocol_, new_socket.get(), ec);
  426. if (!ec)
  427. new_socket.release();
  428. }
  429. return peer;
  430. }
  431. #endif // defined(BOOST_ASIO_HAS_MOVE)
  432. // Start an asynchronous accept. The peer and peer_endpoint objects
  433. // must be valid until the accept's handler is invoked.
  434. template <typename Socket, typename Handler>
  435. void async_accept(implementation_type& impl, Socket& peer,
  436. endpoint_type* peer_endpoint, Handler& handler)
  437. {
  438. // Allocate and construct an operation to wrap the handler.
  439. typedef win_iocp_socket_accept_op<Socket, protocol_type, Handler> op;
  440. typename op::ptr p = { boost::asio::detail::addressof(handler),
  441. op::ptr::allocate(handler), 0 };
  442. bool enable_connection_aborted =
  443. (impl.state_ & socket_ops::enable_connection_aborted) != 0;
  444. p.p = new (p.v) op(*this, impl.socket_, peer, impl.protocol_,
  445. peer_endpoint, enable_connection_aborted, handler);
  446. BOOST_ASIO_HANDLER_CREATION((io_context_, *p.p, "socket",
  447. &impl, impl.socket_, "async_accept"));
  448. start_accept_op(impl, peer.is_open(), p.p->new_socket(),
  449. impl.protocol_.family(), impl.protocol_.type(),
  450. impl.protocol_.protocol(), p.p->output_buffer(),
  451. p.p->address_length(), p.p);
  452. p.v = p.p = 0;
  453. }
  454. #if defined(BOOST_ASIO_HAS_MOVE)
  455. // Start an asynchronous accept. The peer and peer_endpoint objects
  456. // must be valid until the accept's handler is invoked.
  457. template <typename Handler>
  458. void async_accept(implementation_type& impl,
  459. boost::asio::io_context* peer_io_context,
  460. endpoint_type* peer_endpoint, Handler& handler)
  461. {
  462. // Allocate and construct an operation to wrap the handler.
  463. typedef win_iocp_socket_move_accept_op<protocol_type, Handler> op;
  464. typename op::ptr p = { boost::asio::detail::addressof(handler),
  465. op::ptr::allocate(handler), 0 };
  466. bool enable_connection_aborted =
  467. (impl.state_ & socket_ops::enable_connection_aborted) != 0;
  468. p.p = new (p.v) op(*this, impl.socket_, impl.protocol_,
  469. peer_io_context ? *peer_io_context : io_context_,
  470. peer_endpoint, enable_connection_aborted, handler);
  471. BOOST_ASIO_HANDLER_CREATION((io_context_, *p.p, "socket",
  472. &impl, impl.socket_, "async_accept"));
  473. start_accept_op(impl, false, p.p->new_socket(),
  474. impl.protocol_.family(), impl.protocol_.type(),
  475. impl.protocol_.protocol(), p.p->output_buffer(),
  476. p.p->address_length(), p.p);
  477. p.v = p.p = 0;
  478. }
  479. #endif // defined(BOOST_ASIO_HAS_MOVE)
  480. // Connect the socket to the specified endpoint.
  481. boost::system::error_code connect(implementation_type& impl,
  482. const endpoint_type& peer_endpoint, boost::system::error_code& ec)
  483. {
  484. socket_ops::sync_connect(impl.socket_,
  485. peer_endpoint.data(), peer_endpoint.size(), ec);
  486. return ec;
  487. }
  488. // Start an asynchronous connect.
  489. template <typename Handler>
  490. void async_connect(implementation_type& impl,
  491. const endpoint_type& peer_endpoint, Handler& handler)
  492. {
  493. // Allocate and construct an operation to wrap the handler.
  494. typedef win_iocp_socket_connect_op<Handler> op;
  495. typename op::ptr p = { boost::asio::detail::addressof(handler),
  496. op::ptr::allocate(handler), 0 };
  497. p.p = new (p.v) op(impl.socket_, handler);
  498. BOOST_ASIO_HANDLER_CREATION((io_context_, *p.p, "socket",
  499. &impl, impl.socket_, "async_connect"));
  500. start_connect_op(impl, impl.protocol_.family(), impl.protocol_.type(),
  501. peer_endpoint.data(), static_cast<int>(peer_endpoint.size()), p.p);
  502. p.v = p.p = 0;
  503. }
  504. };
  505. } // namespace detail
  506. } // namespace asio
  507. } // namespace boost
  508. #include <boost/asio/detail/pop_options.hpp>
  509. #endif // defined(BOOST_ASIO_HAS_IOCP)
  510. #endif // BOOST_ASIO_DETAIL_WIN_IOCP_SOCKET_SERVICE_HPP