File indexing completed on 2025-01-18 09:28:40
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef BOOST_ASIO_DETAIL_IO_URING_SOCKET_CONNECT_OP_HPP
0012 #define BOOST_ASIO_DETAIL_IO_URING_SOCKET_CONNECT_OP_HPP
0013
0014 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
0015 # pragma once
0016 #endif
0017
0018 #include <boost/asio/detail/config.hpp>
0019
0020 #if defined(BOOST_ASIO_HAS_IO_URING)
0021
0022 #include <boost/asio/detail/bind_handler.hpp>
0023 #include <boost/asio/detail/fenced_block.hpp>
0024 #include <boost/asio/detail/handler_alloc_helpers.hpp>
0025 #include <boost/asio/detail/handler_work.hpp>
0026 #include <boost/asio/detail/io_uring_operation.hpp>
0027 #include <boost/asio/detail/memory.hpp>
0028 #include <boost/asio/detail/socket_ops.hpp>
0029
0030 #include <boost/asio/detail/push_options.hpp>
0031
0032 namespace boost {
0033 namespace asio {
0034 namespace detail {
0035
0036 template <typename Protocol>
0037 class io_uring_socket_connect_op_base : public io_uring_operation
0038 {
0039 public:
0040 io_uring_socket_connect_op_base(const boost::system::error_code& success_ec,
0041 socket_type socket, const typename Protocol::endpoint& endpoint,
0042 func_type complete_func)
0043 : io_uring_operation(success_ec,
0044 &io_uring_socket_connect_op_base::do_prepare,
0045 &io_uring_socket_connect_op_base::do_perform, complete_func),
0046 socket_(socket),
0047 endpoint_(endpoint)
0048 {
0049 }
0050
0051 static void do_prepare(io_uring_operation* base, ::io_uring_sqe* sqe)
0052 {
0053 BOOST_ASIO_ASSUME(base != 0);
0054 io_uring_socket_connect_op_base* o(
0055 static_cast<io_uring_socket_connect_op_base*>(base));
0056
0057 ::io_uring_prep_connect(sqe, o->socket_,
0058 static_cast<sockaddr*>(o->endpoint_.data()),
0059 static_cast<socklen_t>(o->endpoint_.size()));
0060 }
0061
0062 static bool do_perform(io_uring_operation*, bool after_completion)
0063 {
0064 return after_completion;
0065 }
0066
0067 private:
0068 socket_type socket_;
0069 typename Protocol::endpoint endpoint_;
0070 };
0071
0072 template <typename Protocol, typename Handler, typename IoExecutor>
0073 class io_uring_socket_connect_op :
0074 public io_uring_socket_connect_op_base<Protocol>
0075 {
0076 public:
0077 BOOST_ASIO_DEFINE_HANDLER_PTR(io_uring_socket_connect_op);
0078
0079 io_uring_socket_connect_op(const boost::system::error_code& success_ec,
0080 socket_type socket, const typename Protocol::endpoint& endpoint,
0081 Handler& handler, const IoExecutor& io_ex)
0082 : io_uring_socket_connect_op_base<Protocol>(success_ec, socket,
0083 endpoint, &io_uring_socket_connect_op::do_complete),
0084 handler_(static_cast<Handler&&>(handler)),
0085 work_(handler_, io_ex)
0086 {
0087 }
0088
0089 static void do_complete(void* owner, operation* base,
0090 const boost::system::error_code& ,
0091 std::size_t )
0092 {
0093
0094 BOOST_ASIO_ASSUME(base != 0);
0095 io_uring_socket_connect_op* o
0096 (static_cast<io_uring_socket_connect_op*>(base));
0097 ptr p = { boost::asio::detail::addressof(o->handler_), o, o };
0098
0099 BOOST_ASIO_HANDLER_COMPLETION((*o));
0100
0101
0102 handler_work<Handler, IoExecutor> w(
0103 static_cast<handler_work<Handler, IoExecutor>&&>(
0104 o->work_));
0105
0106 BOOST_ASIO_ERROR_LOCATION(o->ec_);
0107
0108
0109
0110
0111
0112
0113
0114 detail::binder1<Handler, boost::system::error_code>
0115 handler(o->handler_, o->ec_);
0116 p.h = boost::asio::detail::addressof(handler.handler_);
0117 p.reset();
0118
0119
0120 if (owner)
0121 {
0122 fenced_block b(fenced_block::half);
0123 BOOST_ASIO_HANDLER_INVOCATION_BEGIN((handler.arg1_));
0124 w.complete(handler, handler.handler_);
0125 BOOST_ASIO_HANDLER_INVOCATION_END;
0126 }
0127 }
0128
0129 private:
0130 Handler handler_;
0131 handler_work<Handler, IoExecutor> work_;
0132 };
0133
0134 }
0135 }
0136 }
0137
0138 #include <boost/asio/detail/pop_options.hpp>
0139
0140 #endif
0141
0142 #endif