]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/asio/detail/impl/reactive_descriptor_service.ipp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / boost / asio / detail / impl / reactive_descriptor_service.ipp
1 //
2 // detail/impl/reactive_descriptor_service.ipp
3 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4 //
5 // Copyright (c) 2003-2022 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_IMPL_REACTIVE_DESCRIPTOR_SERVICE_IPP
12 #define BOOST_ASIO_DETAIL_IMPL_REACTIVE_DESCRIPTOR_SERVICE_IPP
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) \
21 && !defined(BOOST_ASIO_WINDOWS_RUNTIME) \
22 && !defined(__CYGWIN__) \
23 && !defined(BOOST_ASIO_HAS_IO_URING_AS_DEFAULT)
24
25 #include <boost/asio/error.hpp>
26 #include <boost/asio/detail/reactive_descriptor_service.hpp>
27
28 #include <boost/asio/detail/push_options.hpp>
29
30 namespace boost {
31 namespace asio {
32 namespace detail {
33
34 reactive_descriptor_service::reactive_descriptor_service(
35 execution_context& context)
36 : execution_context_service_base<reactive_descriptor_service>(context),
37 reactor_(boost::asio::use_service<reactor>(context))
38 {
39 reactor_.init_task();
40 }
41
42 void reactive_descriptor_service::shutdown()
43 {
44 }
45
46 void reactive_descriptor_service::construct(
47 reactive_descriptor_service::implementation_type& impl)
48 {
49 impl.descriptor_ = -1;
50 impl.state_ = 0;
51 }
52
53 void reactive_descriptor_service::move_construct(
54 reactive_descriptor_service::implementation_type& impl,
55 reactive_descriptor_service::implementation_type& other_impl)
56 BOOST_ASIO_NOEXCEPT
57 {
58 impl.descriptor_ = other_impl.descriptor_;
59 other_impl.descriptor_ = -1;
60
61 impl.state_ = other_impl.state_;
62 other_impl.state_ = 0;
63
64 reactor_.move_descriptor(impl.descriptor_,
65 impl.reactor_data_, other_impl.reactor_data_);
66 }
67
68 void reactive_descriptor_service::move_assign(
69 reactive_descriptor_service::implementation_type& impl,
70 reactive_descriptor_service& other_service,
71 reactive_descriptor_service::implementation_type& other_impl)
72 {
73 destroy(impl);
74
75 impl.descriptor_ = other_impl.descriptor_;
76 other_impl.descriptor_ = -1;
77
78 impl.state_ = other_impl.state_;
79 other_impl.state_ = 0;
80
81 other_service.reactor_.move_descriptor(impl.descriptor_,
82 impl.reactor_data_, other_impl.reactor_data_);
83 }
84
85 void reactive_descriptor_service::destroy(
86 reactive_descriptor_service::implementation_type& impl)
87 {
88 if (is_open(impl))
89 {
90 BOOST_ASIO_HANDLER_OPERATION((reactor_.context(),
91 "descriptor", &impl, impl.descriptor_, "close"));
92
93 reactor_.deregister_descriptor(impl.descriptor_, impl.reactor_data_,
94 (impl.state_ & descriptor_ops::possible_dup) == 0);
95
96 boost::system::error_code ignored_ec;
97 descriptor_ops::close(impl.descriptor_, impl.state_, ignored_ec);
98
99 reactor_.cleanup_descriptor_data(impl.reactor_data_);
100 }
101 }
102
103 boost::system::error_code reactive_descriptor_service::assign(
104 reactive_descriptor_service::implementation_type& impl,
105 const native_handle_type& native_descriptor, boost::system::error_code& ec)
106 {
107 if (is_open(impl))
108 {
109 ec = boost::asio::error::already_open;
110 return ec;
111 }
112
113 if (int err = reactor_.register_descriptor(
114 native_descriptor, impl.reactor_data_))
115 {
116 ec = boost::system::error_code(err,
117 boost::asio::error::get_system_category());
118 return ec;
119 }
120
121 impl.descriptor_ = native_descriptor;
122 impl.state_ = descriptor_ops::possible_dup;
123 ec = boost::system::error_code();
124 return ec;
125 }
126
127 boost::system::error_code reactive_descriptor_service::close(
128 reactive_descriptor_service::implementation_type& impl,
129 boost::system::error_code& ec)
130 {
131 if (is_open(impl))
132 {
133 BOOST_ASIO_HANDLER_OPERATION((reactor_.context(),
134 "descriptor", &impl, impl.descriptor_, "close"));
135
136 reactor_.deregister_descriptor(impl.descriptor_, impl.reactor_data_,
137 (impl.state_ & descriptor_ops::possible_dup) == 0);
138
139 descriptor_ops::close(impl.descriptor_, impl.state_, ec);
140
141 reactor_.cleanup_descriptor_data(impl.reactor_data_);
142 }
143 else
144 {
145 ec = boost::system::error_code();
146 }
147
148 // The descriptor is closed by the OS even if close() returns an error.
149 //
150 // (Actually, POSIX says the state of the descriptor is unspecified. On
151 // Linux the descriptor is apparently closed anyway; e.g. see
152 // http://lkml.org/lkml/2005/9/10/129
153 // We'll just have to assume that other OSes follow the same behaviour.)
154 construct(impl);
155
156 return ec;
157 }
158
159 reactive_descriptor_service::native_handle_type
160 reactive_descriptor_service::release(
161 reactive_descriptor_service::implementation_type& impl)
162 {
163 native_handle_type descriptor = impl.descriptor_;
164
165 if (is_open(impl))
166 {
167 BOOST_ASIO_HANDLER_OPERATION((reactor_.context(),
168 "descriptor", &impl, impl.descriptor_, "release"));
169
170 reactor_.deregister_descriptor(impl.descriptor_, impl.reactor_data_, false);
171 reactor_.cleanup_descriptor_data(impl.reactor_data_);
172 construct(impl);
173 }
174
175 return descriptor;
176 }
177
178 boost::system::error_code reactive_descriptor_service::cancel(
179 reactive_descriptor_service::implementation_type& impl,
180 boost::system::error_code& ec)
181 {
182 if (!is_open(impl))
183 {
184 ec = boost::asio::error::bad_descriptor;
185 return ec;
186 }
187
188 BOOST_ASIO_HANDLER_OPERATION((reactor_.context(),
189 "descriptor", &impl, impl.descriptor_, "cancel"));
190
191 reactor_.cancel_ops(impl.descriptor_, impl.reactor_data_);
192 ec = boost::system::error_code();
193 return ec;
194 }
195
196 void reactive_descriptor_service::start_op(
197 reactive_descriptor_service::implementation_type& impl,
198 int op_type, reactor_op* op, bool is_continuation,
199 bool is_non_blocking, bool noop)
200 {
201 if (!noop)
202 {
203 if ((impl.state_ & descriptor_ops::non_blocking) ||
204 descriptor_ops::set_internal_non_blocking(
205 impl.descriptor_, impl.state_, true, op->ec_))
206 {
207 reactor_.start_op(op_type, impl.descriptor_,
208 impl.reactor_data_, op, is_continuation, is_non_blocking);
209 return;
210 }
211 }
212
213 reactor_.post_immediate_completion(op, is_continuation);
214 }
215
216 } // namespace detail
217 } // namespace asio
218 } // namespace boost
219
220 #include <boost/asio/detail/pop_options.hpp>
221
222 #endif // !defined(BOOST_ASIO_WINDOWS)
223 // && !defined(BOOST_ASIO_WINDOWS_RUNTIME)
224 // && !defined(__CYGWIN__)
225 // && !defined(BOOST_ASIO_HAS_IO_URING_AS_DEFAULT)
226
227 #endif // BOOST_ASIO_DETAIL_IMPL_REACTIVE_DESCRIPTOR_SERVICE_IPP