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