io_uring_socket_service.hpp 21 KB

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