File indexing completed on 2025-01-18 09:28:42
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef BOOST_ASIO_DETAIL_REACTIVE_SOCKET_CONNECT_OP_HPP
0012 #define BOOST_ASIO_DETAIL_REACTIVE_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 #include <boost/asio/detail/bind_handler.hpp>
0020 #include <boost/asio/detail/fenced_block.hpp>
0021 #include <boost/asio/detail/handler_alloc_helpers.hpp>
0022 #include <boost/asio/detail/handler_work.hpp>
0023 #include <boost/asio/detail/memory.hpp>
0024 #include <boost/asio/detail/reactor_op.hpp>
0025 #include <boost/asio/detail/socket_ops.hpp>
0026
0027 #include <boost/asio/detail/push_options.hpp>
0028
0029 namespace boost {
0030 namespace asio {
0031 namespace detail {
0032
0033 class reactive_socket_connect_op_base : public reactor_op
0034 {
0035 public:
0036 reactive_socket_connect_op_base(const boost::system::error_code& success_ec,
0037 socket_type socket, func_type complete_func)
0038 : reactor_op(success_ec,
0039 &reactive_socket_connect_op_base::do_perform, complete_func),
0040 socket_(socket)
0041 {
0042 }
0043
0044 static status do_perform(reactor_op* base)
0045 {
0046 BOOST_ASIO_ASSUME(base != 0);
0047 reactive_socket_connect_op_base* o(
0048 static_cast<reactive_socket_connect_op_base*>(base));
0049
0050 status result = socket_ops::non_blocking_connect(
0051 o->socket_, o->ec_) ? done : not_done;
0052
0053 BOOST_ASIO_HANDLER_REACTOR_OPERATION((*o, "non_blocking_connect", o->ec_));
0054
0055 return result;
0056 }
0057
0058 private:
0059 socket_type socket_;
0060 };
0061
0062 template <typename Handler, typename IoExecutor>
0063 class reactive_socket_connect_op : public reactive_socket_connect_op_base
0064 {
0065 public:
0066 typedef Handler handler_type;
0067 typedef IoExecutor io_executor_type;
0068
0069 BOOST_ASIO_DEFINE_HANDLER_PTR(reactive_socket_connect_op);
0070
0071 reactive_socket_connect_op(const boost::system::error_code& success_ec,
0072 socket_type socket, Handler& handler, const IoExecutor& io_ex)
0073 : reactive_socket_connect_op_base(success_ec, socket,
0074 &reactive_socket_connect_op::do_complete),
0075 handler_(static_cast<Handler&&>(handler)),
0076 work_(handler_, io_ex)
0077 {
0078 }
0079
0080 static void do_complete(void* owner, operation* base,
0081 const boost::system::error_code& ,
0082 std::size_t )
0083 {
0084
0085 BOOST_ASIO_ASSUME(base != 0);
0086 reactive_socket_connect_op* o
0087 (static_cast<reactive_socket_connect_op*>(base));
0088 ptr p = { boost::asio::detail::addressof(o->handler_), o, o };
0089
0090 BOOST_ASIO_HANDLER_COMPLETION((*o));
0091
0092
0093 handler_work<Handler, IoExecutor> w(
0094 static_cast<handler_work<Handler, IoExecutor>&&>(
0095 o->work_));
0096
0097 BOOST_ASIO_ERROR_LOCATION(o->ec_);
0098
0099
0100
0101
0102
0103
0104
0105 detail::binder1<Handler, boost::system::error_code>
0106 handler(o->handler_, o->ec_);
0107 p.h = boost::asio::detail::addressof(handler.handler_);
0108 p.reset();
0109
0110
0111 if (owner)
0112 {
0113 fenced_block b(fenced_block::half);
0114 BOOST_ASIO_HANDLER_INVOCATION_BEGIN((handler.arg1_));
0115 w.complete(handler, handler.handler_);
0116 BOOST_ASIO_HANDLER_INVOCATION_END;
0117 }
0118 }
0119
0120 static void do_immediate(operation* base, bool, const void* io_ex)
0121 {
0122
0123 BOOST_ASIO_ASSUME(base != 0);
0124 reactive_socket_connect_op* o
0125 (static_cast<reactive_socket_connect_op*>(base));
0126 ptr p = { boost::asio::detail::addressof(o->handler_), o, o };
0127
0128 BOOST_ASIO_HANDLER_COMPLETION((*o));
0129
0130
0131 immediate_handler_work<Handler, IoExecutor> w(
0132 static_cast<handler_work<Handler, IoExecutor>&&>(
0133 o->work_));
0134
0135 BOOST_ASIO_ERROR_LOCATION(o->ec_);
0136
0137
0138
0139
0140
0141
0142
0143 detail::binder1<Handler, boost::system::error_code>
0144 handler(o->handler_, o->ec_);
0145 p.h = boost::asio::detail::addressof(handler.handler_);
0146 p.reset();
0147
0148 BOOST_ASIO_HANDLER_INVOCATION_BEGIN((handler.arg1_));
0149 w.complete(handler, handler.handler_, io_ex);
0150 BOOST_ASIO_HANDLER_INVOCATION_END;
0151 }
0152
0153 private:
0154 Handler handler_;
0155 handler_work<Handler, IoExecutor> work_;
0156 };
0157
0158 }
0159 }
0160 }
0161
0162 #include <boost/asio/detail/pop_options.hpp>
0163
0164 #endif