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