]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/asio/detail/reactive_socket_recvmsg_op.hpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / boost / asio / detail / reactive_socket_recvmsg_op.hpp
1 //
2 // detail/reactive_socket_recvmsg_op.hpp
3 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4 //
5 // Copyright (c) 2003-2017 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
11 #ifndef BOOST_ASIO_DETAIL_REACTIVE_SOCKET_RECVMSG_OP_HPP
12 #define BOOST_ASIO_DETAIL_REACTIVE_SOCKET_RECVMSG_OP_HPP
13
14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
15 # pragma once
16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
17
18 #include <boost/asio/detail/config.hpp>
19 #include <boost/asio/detail/bind_handler.hpp>
20 #include <boost/asio/detail/buffer_sequence_adapter.hpp>
21 #include <boost/asio/detail/fenced_block.hpp>
22 #include <boost/asio/detail/memory.hpp>
23 #include <boost/asio/detail/reactor_op.hpp>
24 #include <boost/asio/detail/socket_ops.hpp>
25 #include <boost/asio/socket_base.hpp>
26
27 #include <boost/asio/detail/push_options.hpp>
28
29 namespace boost {
30 namespace asio {
31 namespace detail {
32
33 template <typename MutableBufferSequence>
34 class reactive_socket_recvmsg_op_base : public reactor_op
35 {
36 public:
37 reactive_socket_recvmsg_op_base(socket_type socket,
38 const MutableBufferSequence& buffers, socket_base::message_flags in_flags,
39 socket_base::message_flags& out_flags, func_type complete_func)
40 : reactor_op(&reactive_socket_recvmsg_op_base::do_perform, complete_func),
41 socket_(socket),
42 buffers_(buffers),
43 in_flags_(in_flags),
44 out_flags_(out_flags)
45 {
46 }
47
48 static status do_perform(reactor_op* base)
49 {
50 reactive_socket_recvmsg_op_base* o(
51 static_cast<reactive_socket_recvmsg_op_base*>(base));
52
53 buffer_sequence_adapter<boost::asio::mutable_buffer,
54 MutableBufferSequence> bufs(o->buffers_);
55
56 status result = socket_ops::non_blocking_recvmsg(o->socket_,
57 bufs.buffers(), bufs.count(),
58 o->in_flags_, o->out_flags_,
59 o->ec_, o->bytes_transferred_) ? done : not_done;
60
61 BOOST_ASIO_HANDLER_REACTOR_OPERATION((*o, "non_blocking_recvmsg",
62 o->ec_, o->bytes_transferred_));
63
64 return result;
65 }
66
67 private:
68 socket_type socket_;
69 MutableBufferSequence buffers_;
70 socket_base::message_flags in_flags_;
71 socket_base::message_flags& out_flags_;
72 };
73
74 template <typename MutableBufferSequence, typename Handler>
75 class reactive_socket_recvmsg_op :
76 public reactive_socket_recvmsg_op_base<MutableBufferSequence>
77 {
78 public:
79 BOOST_ASIO_DEFINE_HANDLER_PTR(reactive_socket_recvmsg_op);
80
81 reactive_socket_recvmsg_op(socket_type socket,
82 const MutableBufferSequence& buffers, socket_base::message_flags in_flags,
83 socket_base::message_flags& out_flags, Handler& handler)
84 : reactive_socket_recvmsg_op_base<MutableBufferSequence>(socket, buffers,
85 in_flags, out_flags, &reactive_socket_recvmsg_op::do_complete),
86 handler_(BOOST_ASIO_MOVE_CAST(Handler)(handler))
87 {
88 handler_work<Handler>::start(handler_);
89 }
90
91 static void do_complete(void* owner, operation* base,
92 const boost::system::error_code& /*ec*/,
93 std::size_t /*bytes_transferred*/)
94 {
95 // Take ownership of the handler object.
96 reactive_socket_recvmsg_op* o(
97 static_cast<reactive_socket_recvmsg_op*>(base));
98 ptr p = { boost::asio::detail::addressof(o->handler_), o, o };
99 handler_work<Handler> w(o->handler_);
100
101 BOOST_ASIO_HANDLER_COMPLETION((*o));
102
103 // Make a copy of the handler so that the memory can be deallocated before
104 // the upcall is made. Even if we're not about to make an upcall, a
105 // sub-object of the handler may be the true owner of the memory associated
106 // with the handler. Consequently, a local copy of the handler is required
107 // to ensure that any owning sub-object remains valid until after we have
108 // deallocated the memory here.
109 detail::binder2<Handler, boost::system::error_code, std::size_t>
110 handler(o->handler_, o->ec_, o->bytes_transferred_);
111 p.h = boost::asio::detail::addressof(handler.handler_);
112 p.reset();
113
114 // Make the upcall if required.
115 if (owner)
116 {
117 fenced_block b(fenced_block::half);
118 BOOST_ASIO_HANDLER_INVOCATION_BEGIN((handler.arg1_, handler.arg2_));
119 w.complete(handler, handler.handler_);
120 BOOST_ASIO_HANDLER_INVOCATION_END;
121 }
122 }
123
124 private:
125 Handler handler_;
126 };
127
128 } // namespace detail
129 } // namespace asio
130 } // namespace boost
131
132 #include <boost/asio/detail/pop_options.hpp>
133
134 #endif // BOOST_ASIO_DETAIL_REACTIVE_SOCKET_RECVMSG_OP_HPP