]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // |
2 | // detail/reactive_socket_service_base.hpp | |
3 | // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
4 | // | |
f67539c2 | 5 | // Copyright (c) 2003-2020 Christopher M. Kohlhoff (chris at kohlhoff dot com) |
7c673cae FG |
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_SERVICE_BASE_HPP | |
12 | #define BOOST_ASIO_DETAIL_REACTIVE_SOCKET_SERVICE_BASE_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_HAS_IOCP) \ | |
21 | && !defined(BOOST_ASIO_WINDOWS_RUNTIME) | |
22 | ||
23 | #include <boost/asio/buffer.hpp> | |
24 | #include <boost/asio/error.hpp> | |
92f5a8d4 | 25 | #include <boost/asio/execution_context.hpp> |
7c673cae | 26 | #include <boost/asio/socket_base.hpp> |
7c673cae | 27 | #include <boost/asio/detail/buffer_sequence_adapter.hpp> |
b32b8144 | 28 | #include <boost/asio/detail/memory.hpp> |
7c673cae FG |
29 | #include <boost/asio/detail/reactive_null_buffers_op.hpp> |
30 | #include <boost/asio/detail/reactive_socket_recv_op.hpp> | |
31 | #include <boost/asio/detail/reactive_socket_recvmsg_op.hpp> | |
32 | #include <boost/asio/detail/reactive_socket_send_op.hpp> | |
b32b8144 | 33 | #include <boost/asio/detail/reactive_wait_op.hpp> |
7c673cae FG |
34 | #include <boost/asio/detail/reactor.hpp> |
35 | #include <boost/asio/detail/reactor_op.hpp> | |
36 | #include <boost/asio/detail/socket_holder.hpp> | |
37 | #include <boost/asio/detail/socket_ops.hpp> | |
38 | #include <boost/asio/detail/socket_types.hpp> | |
39 | ||
40 | #include <boost/asio/detail/push_options.hpp> | |
41 | ||
42 | namespace boost { | |
43 | namespace asio { | |
44 | namespace detail { | |
45 | ||
46 | class reactive_socket_service_base | |
47 | { | |
48 | public: | |
49 | // The native type of a socket. | |
50 | typedef socket_type native_handle_type; | |
51 | ||
52 | // The implementation type of the socket. | |
53 | struct base_implementation_type | |
54 | { | |
55 | // The native socket representation. | |
56 | socket_type socket_; | |
57 | ||
58 | // The current state of the socket. | |
59 | socket_ops::state_type state_; | |
60 | ||
61 | // Per-descriptor data used by the reactor. | |
62 | reactor::per_descriptor_data reactor_data_; | |
63 | }; | |
64 | ||
65 | // Constructor. | |
92f5a8d4 | 66 | BOOST_ASIO_DECL reactive_socket_service_base(execution_context& context); |
7c673cae FG |
67 | |
68 | // Destroy all user-defined handler objects owned by the service. | |
b32b8144 | 69 | BOOST_ASIO_DECL void base_shutdown(); |
7c673cae FG |
70 | |
71 | // Construct a new socket implementation. | |
72 | BOOST_ASIO_DECL void construct(base_implementation_type& impl); | |
73 | ||
74 | // Move-construct a new socket implementation. | |
75 | BOOST_ASIO_DECL void base_move_construct(base_implementation_type& impl, | |
92f5a8d4 | 76 | base_implementation_type& other_impl) BOOST_ASIO_NOEXCEPT; |
7c673cae FG |
77 | |
78 | // Move-assign from another socket implementation. | |
79 | BOOST_ASIO_DECL void base_move_assign(base_implementation_type& impl, | |
80 | reactive_socket_service_base& other_service, | |
81 | base_implementation_type& other_impl); | |
82 | ||
83 | // Destroy a socket implementation. | |
84 | BOOST_ASIO_DECL void destroy(base_implementation_type& impl); | |
85 | ||
86 | // Determine whether the socket is open. | |
87 | bool is_open(const base_implementation_type& impl) const | |
88 | { | |
89 | return impl.socket_ != invalid_socket; | |
90 | } | |
91 | ||
92 | // Destroy a socket implementation. | |
93 | BOOST_ASIO_DECL boost::system::error_code close( | |
94 | base_implementation_type& impl, boost::system::error_code& ec); | |
95 | ||
b32b8144 FG |
96 | // Release ownership of the socket. |
97 | BOOST_ASIO_DECL socket_type release( | |
98 | base_implementation_type& impl, boost::system::error_code& ec); | |
99 | ||
7c673cae FG |
100 | // Get the native socket representation. |
101 | native_handle_type native_handle(base_implementation_type& impl) | |
102 | { | |
103 | return impl.socket_; | |
104 | } | |
105 | ||
106 | // Cancel all operations associated with the socket. | |
107 | BOOST_ASIO_DECL boost::system::error_code cancel( | |
108 | base_implementation_type& impl, boost::system::error_code& ec); | |
109 | ||
110 | // Determine whether the socket is at the out-of-band data mark. | |
111 | bool at_mark(const base_implementation_type& impl, | |
112 | boost::system::error_code& ec) const | |
113 | { | |
114 | return socket_ops::sockatmark(impl.socket_, ec); | |
115 | } | |
116 | ||
117 | // Determine the number of bytes available for reading. | |
118 | std::size_t available(const base_implementation_type& impl, | |
119 | boost::system::error_code& ec) const | |
120 | { | |
121 | return socket_ops::available(impl.socket_, ec); | |
122 | } | |
123 | ||
124 | // Place the socket into the state where it will listen for new connections. | |
125 | boost::system::error_code listen(base_implementation_type& impl, | |
126 | int backlog, boost::system::error_code& ec) | |
127 | { | |
128 | socket_ops::listen(impl.socket_, backlog, ec); | |
129 | return ec; | |
130 | } | |
131 | ||
132 | // Perform an IO control command on the socket. | |
133 | template <typename IO_Control_Command> | |
134 | boost::system::error_code io_control(base_implementation_type& impl, | |
135 | IO_Control_Command& command, boost::system::error_code& ec) | |
136 | { | |
137 | socket_ops::ioctl(impl.socket_, impl.state_, command.name(), | |
138 | static_cast<ioctl_arg_type*>(command.data()), ec); | |
139 | return ec; | |
140 | } | |
141 | ||
142 | // Gets the non-blocking mode of the socket. | |
143 | bool non_blocking(const base_implementation_type& impl) const | |
144 | { | |
145 | return (impl.state_ & socket_ops::user_set_non_blocking) != 0; | |
146 | } | |
147 | ||
148 | // Sets the non-blocking mode of the socket. | |
149 | boost::system::error_code non_blocking(base_implementation_type& impl, | |
150 | bool mode, boost::system::error_code& ec) | |
151 | { | |
152 | socket_ops::set_user_non_blocking(impl.socket_, impl.state_, mode, ec); | |
153 | return ec; | |
154 | } | |
155 | ||
156 | // Gets the non-blocking mode of the native socket implementation. | |
157 | bool native_non_blocking(const base_implementation_type& impl) const | |
158 | { | |
159 | return (impl.state_ & socket_ops::internal_non_blocking) != 0; | |
160 | } | |
161 | ||
162 | // Sets the non-blocking mode of the native socket implementation. | |
163 | boost::system::error_code native_non_blocking(base_implementation_type& impl, | |
164 | bool mode, boost::system::error_code& ec) | |
165 | { | |
166 | socket_ops::set_internal_non_blocking(impl.socket_, impl.state_, mode, ec); | |
167 | return ec; | |
168 | } | |
169 | ||
b32b8144 FG |
170 | // Wait for the socket to become ready to read, ready to write, or to have |
171 | // pending error conditions. | |
172 | boost::system::error_code wait(base_implementation_type& impl, | |
173 | socket_base::wait_type w, boost::system::error_code& ec) | |
7c673cae | 174 | { |
b32b8144 FG |
175 | switch (w) |
176 | { | |
177 | case socket_base::wait_read: | |
178 | socket_ops::poll_read(impl.socket_, impl.state_, -1, ec); | |
179 | break; | |
180 | case socket_base::wait_write: | |
181 | socket_ops::poll_write(impl.socket_, impl.state_, -1, ec); | |
182 | break; | |
183 | case socket_base::wait_error: | |
184 | socket_ops::poll_error(impl.socket_, impl.state_, -1, ec); | |
185 | break; | |
186 | default: | |
187 | ec = boost::asio::error::invalid_argument; | |
188 | break; | |
189 | } | |
190 | ||
7c673cae FG |
191 | return ec; |
192 | } | |
193 | ||
b32b8144 FG |
194 | // Asynchronously wait for the socket to become ready to read, ready to |
195 | // write, or to have pending error conditions. | |
92f5a8d4 | 196 | template <typename Handler, typename IoExecutor> |
b32b8144 | 197 | void async_wait(base_implementation_type& impl, |
92f5a8d4 | 198 | socket_base::wait_type w, Handler& handler, const IoExecutor& io_ex) |
b32b8144 FG |
199 | { |
200 | bool is_continuation = | |
201 | boost_asio_handler_cont_helpers::is_continuation(handler); | |
202 | ||
203 | // Allocate and construct an operation to wrap the handler. | |
92f5a8d4 | 204 | typedef reactive_wait_op<Handler, IoExecutor> op; |
b32b8144 FG |
205 | typename op::ptr p = { boost::asio::detail::addressof(handler), |
206 | op::ptr::allocate(handler), 0 }; | |
20effc67 | 207 | p.p = new (p.v) op(success_ec_, handler, io_ex); |
b32b8144 FG |
208 | |
209 | BOOST_ASIO_HANDLER_CREATION((reactor_.context(), *p.p, "socket", | |
210 | &impl, impl.socket_, "async_wait")); | |
211 | ||
212 | int op_type; | |
213 | switch (w) | |
214 | { | |
215 | case socket_base::wait_read: | |
216 | op_type = reactor::read_op; | |
217 | break; | |
218 | case socket_base::wait_write: | |
219 | op_type = reactor::write_op; | |
220 | break; | |
221 | case socket_base::wait_error: | |
222 | op_type = reactor::except_op; | |
223 | break; | |
224 | default: | |
225 | p.p->ec_ = boost::asio::error::invalid_argument; | |
226 | reactor_.post_immediate_completion(p.p, is_continuation); | |
227 | p.v = p.p = 0; | |
228 | return; | |
229 | } | |
230 | ||
231 | start_op(impl, op_type, p.p, is_continuation, false, false); | |
232 | p.v = p.p = 0; | |
233 | } | |
234 | ||
7c673cae FG |
235 | // Send the given data to the peer. |
236 | template <typename ConstBufferSequence> | |
237 | size_t send(base_implementation_type& impl, | |
238 | const ConstBufferSequence& buffers, | |
239 | socket_base::message_flags flags, boost::system::error_code& ec) | |
240 | { | |
20effc67 TL |
241 | typedef buffer_sequence_adapter<boost::asio::const_buffer, |
242 | ConstBufferSequence> bufs_type; | |
7c673cae | 243 | |
20effc67 TL |
244 | if (bufs_type::is_single_buffer) |
245 | { | |
246 | return socket_ops::sync_send1(impl.socket_, | |
247 | impl.state_, bufs_type::first(buffers).data(), | |
248 | bufs_type::first(buffers).size(), flags, ec); | |
249 | } | |
250 | else | |
251 | { | |
252 | bufs_type bufs(buffers); | |
253 | return socket_ops::sync_send(impl.socket_, impl.state_, | |
254 | bufs.buffers(), bufs.count(), flags, bufs.all_empty(), ec); | |
255 | } | |
7c673cae FG |
256 | } |
257 | ||
258 | // Wait until data can be sent without blocking. | |
259 | size_t send(base_implementation_type& impl, const null_buffers&, | |
260 | socket_base::message_flags, boost::system::error_code& ec) | |
261 | { | |
262 | // Wait for socket to become ready. | |
b32b8144 | 263 | socket_ops::poll_write(impl.socket_, impl.state_, -1, ec); |
7c673cae FG |
264 | |
265 | return 0; | |
266 | } | |
267 | ||
268 | // Start an asynchronous send. The data being sent must be valid for the | |
269 | // lifetime of the asynchronous operation. | |
92f5a8d4 | 270 | template <typename ConstBufferSequence, typename Handler, typename IoExecutor> |
7c673cae | 271 | void async_send(base_implementation_type& impl, |
92f5a8d4 TL |
272 | const ConstBufferSequence& buffers, socket_base::message_flags flags, |
273 | Handler& handler, const IoExecutor& io_ex) | |
7c673cae FG |
274 | { |
275 | bool is_continuation = | |
276 | boost_asio_handler_cont_helpers::is_continuation(handler); | |
277 | ||
278 | // Allocate and construct an operation to wrap the handler. | |
92f5a8d4 TL |
279 | typedef reactive_socket_send_op< |
280 | ConstBufferSequence, Handler, IoExecutor> op; | |
7c673cae | 281 | typename op::ptr p = { boost::asio::detail::addressof(handler), |
b32b8144 | 282 | op::ptr::allocate(handler), 0 }; |
20effc67 TL |
283 | p.p = new (p.v) op(success_ec_, impl.socket_, |
284 | impl.state_, buffers, flags, handler, io_ex); | |
7c673cae | 285 | |
b32b8144 FG |
286 | BOOST_ASIO_HANDLER_CREATION((reactor_.context(), *p.p, "socket", |
287 | &impl, impl.socket_, "async_send")); | |
7c673cae FG |
288 | |
289 | start_op(impl, reactor::write_op, p.p, is_continuation, true, | |
290 | ((impl.state_ & socket_ops::stream_oriented) | |
291 | && buffer_sequence_adapter<boost::asio::const_buffer, | |
292 | ConstBufferSequence>::all_empty(buffers))); | |
293 | p.v = p.p = 0; | |
294 | } | |
295 | ||
296 | // Start an asynchronous wait until data can be sent without blocking. | |
92f5a8d4 | 297 | template <typename Handler, typename IoExecutor> |
7c673cae | 298 | void async_send(base_implementation_type& impl, const null_buffers&, |
92f5a8d4 | 299 | socket_base::message_flags, Handler& handler, const IoExecutor& io_ex) |
7c673cae FG |
300 | { |
301 | bool is_continuation = | |
302 | boost_asio_handler_cont_helpers::is_continuation(handler); | |
303 | ||
304 | // Allocate and construct an operation to wrap the handler. | |
92f5a8d4 | 305 | typedef reactive_null_buffers_op<Handler, IoExecutor> op; |
7c673cae | 306 | typename op::ptr p = { boost::asio::detail::addressof(handler), |
b32b8144 | 307 | op::ptr::allocate(handler), 0 }; |
20effc67 | 308 | p.p = new (p.v) op(success_ec_, handler, io_ex); |
7c673cae | 309 | |
b32b8144 FG |
310 | BOOST_ASIO_HANDLER_CREATION((reactor_.context(), *p.p, "socket", |
311 | &impl, impl.socket_, "async_send(null_buffers)")); | |
7c673cae FG |
312 | |
313 | start_op(impl, reactor::write_op, p.p, is_continuation, false, false); | |
314 | p.v = p.p = 0; | |
315 | } | |
316 | ||
317 | // Receive some data from the peer. Returns the number of bytes received. | |
318 | template <typename MutableBufferSequence> | |
319 | size_t receive(base_implementation_type& impl, | |
320 | const MutableBufferSequence& buffers, | |
321 | socket_base::message_flags flags, boost::system::error_code& ec) | |
322 | { | |
20effc67 TL |
323 | typedef buffer_sequence_adapter<boost::asio::mutable_buffer, |
324 | MutableBufferSequence> bufs_type; | |
7c673cae | 325 | |
20effc67 TL |
326 | if (bufs_type::is_single_buffer) |
327 | { | |
328 | return socket_ops::sync_recv1(impl.socket_, | |
329 | impl.state_, bufs_type::first(buffers).data(), | |
330 | bufs_type::first(buffers).size(), flags, ec); | |
331 | } | |
332 | else | |
333 | { | |
334 | bufs_type bufs(buffers); | |
335 | return socket_ops::sync_recv(impl.socket_, impl.state_, | |
336 | bufs.buffers(), bufs.count(), flags, bufs.all_empty(), ec); | |
337 | } | |
7c673cae FG |
338 | } |
339 | ||
340 | // Wait until data can be received without blocking. | |
341 | size_t receive(base_implementation_type& impl, const null_buffers&, | |
342 | socket_base::message_flags, boost::system::error_code& ec) | |
343 | { | |
344 | // Wait for socket to become ready. | |
b32b8144 | 345 | socket_ops::poll_read(impl.socket_, impl.state_, -1, ec); |
7c673cae FG |
346 | |
347 | return 0; | |
348 | } | |
349 | ||
350 | // Start an asynchronous receive. The buffer for the data being received | |
351 | // must be valid for the lifetime of the asynchronous operation. | |
92f5a8d4 TL |
352 | template <typename MutableBufferSequence, |
353 | typename Handler, typename IoExecutor> | |
7c673cae | 354 | void async_receive(base_implementation_type& impl, |
92f5a8d4 TL |
355 | const MutableBufferSequence& buffers, socket_base::message_flags flags, |
356 | Handler& handler, const IoExecutor& io_ex) | |
7c673cae FG |
357 | { |
358 | bool is_continuation = | |
359 | boost_asio_handler_cont_helpers::is_continuation(handler); | |
360 | ||
361 | // Allocate and construct an operation to wrap the handler. | |
92f5a8d4 TL |
362 | typedef reactive_socket_recv_op< |
363 | MutableBufferSequence, Handler, IoExecutor> op; | |
7c673cae | 364 | typename op::ptr p = { boost::asio::detail::addressof(handler), |
b32b8144 | 365 | op::ptr::allocate(handler), 0 }; |
20effc67 TL |
366 | p.p = new (p.v) op(success_ec_, impl.socket_, |
367 | impl.state_, buffers, flags, handler, io_ex); | |
7c673cae | 368 | |
b32b8144 FG |
369 | BOOST_ASIO_HANDLER_CREATION((reactor_.context(), *p.p, "socket", |
370 | &impl, impl.socket_, "async_receive")); | |
7c673cae FG |
371 | |
372 | start_op(impl, | |
373 | (flags & socket_base::message_out_of_band) | |
374 | ? reactor::except_op : reactor::read_op, | |
375 | p.p, is_continuation, | |
376 | (flags & socket_base::message_out_of_band) == 0, | |
377 | ((impl.state_ & socket_ops::stream_oriented) | |
378 | && buffer_sequence_adapter<boost::asio::mutable_buffer, | |
379 | MutableBufferSequence>::all_empty(buffers))); | |
380 | p.v = p.p = 0; | |
381 | } | |
382 | ||
383 | // Wait until data can be received without blocking. | |
92f5a8d4 TL |
384 | template <typename Handler, typename IoExecutor> |
385 | void async_receive(base_implementation_type& impl, | |
386 | const null_buffers&, socket_base::message_flags flags, | |
387 | Handler& handler, const IoExecutor& io_ex) | |
7c673cae FG |
388 | { |
389 | bool is_continuation = | |
390 | boost_asio_handler_cont_helpers::is_continuation(handler); | |
391 | ||
392 | // Allocate and construct an operation to wrap the handler. | |
92f5a8d4 | 393 | typedef reactive_null_buffers_op<Handler, IoExecutor> op; |
7c673cae | 394 | typename op::ptr p = { boost::asio::detail::addressof(handler), |
b32b8144 | 395 | op::ptr::allocate(handler), 0 }; |
20effc67 | 396 | p.p = new (p.v) op(success_ec_, handler, io_ex); |
7c673cae | 397 | |
b32b8144 FG |
398 | BOOST_ASIO_HANDLER_CREATION((reactor_.context(), *p.p, "socket", |
399 | &impl, impl.socket_, "async_receive(null_buffers)")); | |
7c673cae FG |
400 | |
401 | start_op(impl, | |
402 | (flags & socket_base::message_out_of_band) | |
403 | ? reactor::except_op : reactor::read_op, | |
404 | p.p, is_continuation, false, false); | |
405 | p.v = p.p = 0; | |
406 | } | |
407 | ||
408 | // Receive some data with associated flags. Returns the number of bytes | |
409 | // received. | |
410 | template <typename MutableBufferSequence> | |
411 | size_t receive_with_flags(base_implementation_type& impl, | |
412 | const MutableBufferSequence& buffers, | |
413 | socket_base::message_flags in_flags, | |
414 | socket_base::message_flags& out_flags, boost::system::error_code& ec) | |
415 | { | |
416 | buffer_sequence_adapter<boost::asio::mutable_buffer, | |
417 | MutableBufferSequence> bufs(buffers); | |
418 | ||
419 | return socket_ops::sync_recvmsg(impl.socket_, impl.state_, | |
420 | bufs.buffers(), bufs.count(), in_flags, out_flags, ec); | |
421 | } | |
422 | ||
423 | // Wait until data can be received without blocking. | |
424 | size_t receive_with_flags(base_implementation_type& impl, | |
425 | const null_buffers&, socket_base::message_flags, | |
426 | socket_base::message_flags& out_flags, boost::system::error_code& ec) | |
427 | { | |
428 | // Wait for socket to become ready. | |
b32b8144 | 429 | socket_ops::poll_read(impl.socket_, impl.state_, -1, ec); |
7c673cae FG |
430 | |
431 | // Clear out_flags, since we cannot give it any other sensible value when | |
432 | // performing a null_buffers operation. | |
433 | out_flags = 0; | |
434 | ||
435 | return 0; | |
436 | } | |
437 | ||
438 | // Start an asynchronous receive. The buffer for the data being received | |
439 | // must be valid for the lifetime of the asynchronous operation. | |
92f5a8d4 TL |
440 | template <typename MutableBufferSequence, |
441 | typename Handler, typename IoExecutor> | |
7c673cae FG |
442 | void async_receive_with_flags(base_implementation_type& impl, |
443 | const MutableBufferSequence& buffers, socket_base::message_flags in_flags, | |
92f5a8d4 TL |
444 | socket_base::message_flags& out_flags, Handler& handler, |
445 | const IoExecutor& io_ex) | |
7c673cae FG |
446 | { |
447 | bool is_continuation = | |
448 | boost_asio_handler_cont_helpers::is_continuation(handler); | |
449 | ||
450 | // Allocate and construct an operation to wrap the handler. | |
92f5a8d4 TL |
451 | typedef reactive_socket_recvmsg_op< |
452 | MutableBufferSequence, Handler, IoExecutor> op; | |
7c673cae | 453 | typename op::ptr p = { boost::asio::detail::addressof(handler), |
b32b8144 | 454 | op::ptr::allocate(handler), 0 }; |
20effc67 TL |
455 | p.p = new (p.v) op(success_ec_, impl.socket_, |
456 | buffers, in_flags, out_flags, handler, io_ex); | |
7c673cae | 457 | |
b32b8144 FG |
458 | BOOST_ASIO_HANDLER_CREATION((reactor_.context(), *p.p, "socket", |
459 | &impl, impl.socket_, "async_receive_with_flags")); | |
7c673cae FG |
460 | |
461 | start_op(impl, | |
462 | (in_flags & socket_base::message_out_of_band) | |
463 | ? reactor::except_op : reactor::read_op, | |
464 | p.p, is_continuation, | |
465 | (in_flags & socket_base::message_out_of_band) == 0, false); | |
466 | p.v = p.p = 0; | |
467 | } | |
468 | ||
469 | // Wait until data can be received without blocking. | |
92f5a8d4 | 470 | template <typename Handler, typename IoExecutor> |
7c673cae FG |
471 | void async_receive_with_flags(base_implementation_type& impl, |
472 | const null_buffers&, socket_base::message_flags in_flags, | |
92f5a8d4 TL |
473 | socket_base::message_flags& out_flags, Handler& handler, |
474 | const IoExecutor& io_ex) | |
7c673cae FG |
475 | { |
476 | bool is_continuation = | |
477 | boost_asio_handler_cont_helpers::is_continuation(handler); | |
478 | ||
479 | // Allocate and construct an operation to wrap the handler. | |
92f5a8d4 | 480 | typedef reactive_null_buffers_op<Handler, IoExecutor> op; |
7c673cae | 481 | typename op::ptr p = { boost::asio::detail::addressof(handler), |
b32b8144 | 482 | op::ptr::allocate(handler), 0 }; |
20effc67 | 483 | p.p = new (p.v) op(success_ec_, handler, io_ex); |
7c673cae | 484 | |
b32b8144 FG |
485 | BOOST_ASIO_HANDLER_CREATION((reactor_.context(), *p.p, "socket", |
486 | &impl, impl.socket_, "async_receive_with_flags(null_buffers)")); | |
7c673cae FG |
487 | |
488 | // Clear out_flags, since we cannot give it any other sensible value when | |
489 | // performing a null_buffers operation. | |
490 | out_flags = 0; | |
491 | ||
492 | start_op(impl, | |
493 | (in_flags & socket_base::message_out_of_band) | |
494 | ? reactor::except_op : reactor::read_op, | |
495 | p.p, is_continuation, false, false); | |
496 | p.v = p.p = 0; | |
497 | } | |
498 | ||
499 | protected: | |
500 | // Open a new socket implementation. | |
501 | BOOST_ASIO_DECL boost::system::error_code do_open( | |
502 | base_implementation_type& impl, int af, | |
503 | int type, int protocol, boost::system::error_code& ec); | |
504 | ||
505 | // Assign a native socket to a socket implementation. | |
506 | BOOST_ASIO_DECL boost::system::error_code do_assign( | |
507 | base_implementation_type& impl, int type, | |
508 | const native_handle_type& native_socket, boost::system::error_code& ec); | |
509 | ||
510 | // Start the asynchronous read or write operation. | |
511 | BOOST_ASIO_DECL void start_op(base_implementation_type& impl, int op_type, | |
512 | reactor_op* op, bool is_continuation, bool is_non_blocking, bool noop); | |
513 | ||
514 | // Start the asynchronous accept operation. | |
515 | BOOST_ASIO_DECL void start_accept_op(base_implementation_type& impl, | |
516 | reactor_op* op, bool is_continuation, bool peer_is_open); | |
517 | ||
518 | // Start the asynchronous connect operation. | |
519 | BOOST_ASIO_DECL void start_connect_op(base_implementation_type& impl, | |
520 | reactor_op* op, bool is_continuation, | |
521 | const socket_addr_type* addr, size_t addrlen); | |
522 | ||
523 | // The selector that performs event demultiplexing for the service. | |
524 | reactor& reactor_; | |
20effc67 TL |
525 | |
526 | // Cached success value to avoid accessing category singleton. | |
527 | const boost::system::error_code success_ec_; | |
7c673cae FG |
528 | }; |
529 | ||
530 | } // namespace detail | |
531 | } // namespace asio | |
532 | } // namespace boost | |
533 | ||
534 | #include <boost/asio/detail/pop_options.hpp> | |
535 | ||
536 | #if defined(BOOST_ASIO_HEADER_ONLY) | |
537 | # include <boost/asio/detail/impl/reactive_socket_service_base.ipp> | |
538 | #endif // defined(BOOST_ASIO_HEADER_ONLY) | |
539 | ||
540 | #endif // !defined(BOOST_ASIO_HAS_IOCP) | |
541 | // && !defined(BOOST_ASIO_WINDOWS_RUNTIME) | |
542 | ||
543 | #endif // BOOST_ASIO_DETAIL_REACTIVE_SOCKET_SERVICE_BASE_HPP |