File indexing completed on 2025-01-18 09:28:46
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef BOOST_ASIO_DETAIL_WIN_IOCP_SOCKET_CONNECT_OP_HPP
0012 #define BOOST_ASIO_DETAIL_WIN_IOCP_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_IOCP)
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/memory.hpp>
0027 #include <boost/asio/detail/reactor_op.hpp>
0028 #include <boost/asio/detail/socket_ops.hpp>
0029 #include <boost/asio/error.hpp>
0030
0031 #include <boost/asio/detail/push_options.hpp>
0032
0033 namespace boost {
0034 namespace asio {
0035 namespace detail {
0036
0037 class win_iocp_socket_connect_op_base : public reactor_op
0038 {
0039 public:
0040 win_iocp_socket_connect_op_base(socket_type socket, func_type complete_func)
0041 : reactor_op(boost::system::error_code(),
0042 &win_iocp_socket_connect_op_base::do_perform, complete_func),
0043 socket_(socket),
0044 connect_ex_(false)
0045 {
0046 }
0047
0048 static status do_perform(reactor_op* base)
0049 {
0050 BOOST_ASIO_ASSUME(base != 0);
0051 win_iocp_socket_connect_op_base* o(
0052 static_cast<win_iocp_socket_connect_op_base*>(base));
0053
0054 return socket_ops::non_blocking_connect(
0055 o->socket_, o->ec_) ? done : not_done;
0056 }
0057
0058 socket_type socket_;
0059 bool connect_ex_;
0060 };
0061
0062 template <typename Handler, typename IoExecutor>
0063 class win_iocp_socket_connect_op : public win_iocp_socket_connect_op_base
0064 {
0065 public:
0066 BOOST_ASIO_DEFINE_HANDLER_PTR(win_iocp_socket_connect_op);
0067
0068 win_iocp_socket_connect_op(socket_type socket,
0069 Handler& handler, const IoExecutor& io_ex)
0070 : win_iocp_socket_connect_op_base(socket,
0071 &win_iocp_socket_connect_op::do_complete),
0072 handler_(static_cast<Handler&&>(handler)),
0073 work_(handler_, io_ex)
0074 {
0075 }
0076
0077 static void do_complete(void* owner, operation* base,
0078 const boost::system::error_code& result_ec,
0079 std::size_t )
0080 {
0081 boost::system::error_code ec(result_ec);
0082
0083
0084 BOOST_ASIO_ASSUME(base != 0);
0085 win_iocp_socket_connect_op* o(
0086 static_cast<win_iocp_socket_connect_op*>(base));
0087 ptr p = { boost::asio::detail::addressof(o->handler_), o, o };
0088
0089 if (owner)
0090 {
0091 if (o->connect_ex_)
0092 socket_ops::complete_iocp_connect(o->socket_, ec);
0093 else
0094 ec = o->ec_;
0095 }
0096
0097 BOOST_ASIO_HANDLER_COMPLETION((*o));
0098
0099
0100 handler_work<Handler, IoExecutor> w(
0101 static_cast<handler_work<Handler, IoExecutor>&&>(
0102 o->work_));
0103
0104 BOOST_ASIO_ERROR_LOCATION(ec);
0105
0106
0107
0108
0109
0110
0111
0112 detail::binder1<Handler, boost::system::error_code>
0113 handler(o->handler_, ec);
0114 p.h = boost::asio::detail::addressof(handler.handler_);
0115 p.reset();
0116
0117
0118 if (owner)
0119 {
0120 fenced_block b(fenced_block::half);
0121 BOOST_ASIO_HANDLER_INVOCATION_BEGIN((handler.arg1_));
0122 w.complete(handler, handler.handler_);
0123 BOOST_ASIO_HANDLER_INVOCATION_END;
0124 }
0125 }
0126
0127 private:
0128 Handler handler_;
0129 handler_work<Handler, IoExecutor> work_;
0130 };
0131
0132 }
0133 }
0134 }
0135
0136 #include <boost/asio/detail/pop_options.hpp>
0137
0138 #endif
0139
0140 #endif