Chris@16
|
1 //
|
Chris@16
|
2 // detail/reactive_socket_service_base.hpp
|
Chris@16
|
3 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
Chris@16
|
4 //
|
Chris@101
|
5 // Copyright (c) 2003-2015 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
Chris@16
|
6 //
|
Chris@16
|
7 // Distributed under the Boost Software License, Version 1.0. (See accompanying
|
Chris@16
|
8 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
9 //
|
Chris@16
|
10
|
Chris@16
|
11 #ifndef BOOST_ASIO_DETAIL_REACTIVE_SOCKET_SERVICE_BASE_HPP
|
Chris@16
|
12 #define BOOST_ASIO_DETAIL_REACTIVE_SOCKET_SERVICE_BASE_HPP
|
Chris@16
|
13
|
Chris@16
|
14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
Chris@16
|
15 # pragma once
|
Chris@16
|
16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
Chris@16
|
17
|
Chris@16
|
18 #include <boost/asio/detail/config.hpp>
|
Chris@16
|
19
|
Chris@16
|
20 #if !defined(BOOST_ASIO_HAS_IOCP) \
|
Chris@16
|
21 && !defined(BOOST_ASIO_WINDOWS_RUNTIME)
|
Chris@16
|
22
|
Chris@16
|
23 #include <boost/asio/buffer.hpp>
|
Chris@16
|
24 #include <boost/asio/error.hpp>
|
Chris@16
|
25 #include <boost/asio/io_service.hpp>
|
Chris@16
|
26 #include <boost/asio/socket_base.hpp>
|
Chris@16
|
27 #include <boost/asio/detail/addressof.hpp>
|
Chris@16
|
28 #include <boost/asio/detail/buffer_sequence_adapter.hpp>
|
Chris@16
|
29 #include <boost/asio/detail/reactive_null_buffers_op.hpp>
|
Chris@16
|
30 #include <boost/asio/detail/reactive_socket_recv_op.hpp>
|
Chris@16
|
31 #include <boost/asio/detail/reactive_socket_recvmsg_op.hpp>
|
Chris@16
|
32 #include <boost/asio/detail/reactive_socket_send_op.hpp>
|
Chris@16
|
33 #include <boost/asio/detail/reactor.hpp>
|
Chris@16
|
34 #include <boost/asio/detail/reactor_op.hpp>
|
Chris@16
|
35 #include <boost/asio/detail/socket_holder.hpp>
|
Chris@16
|
36 #include <boost/asio/detail/socket_ops.hpp>
|
Chris@16
|
37 #include <boost/asio/detail/socket_types.hpp>
|
Chris@16
|
38
|
Chris@16
|
39 #include <boost/asio/detail/push_options.hpp>
|
Chris@16
|
40
|
Chris@16
|
41 namespace boost {
|
Chris@16
|
42 namespace asio {
|
Chris@16
|
43 namespace detail {
|
Chris@16
|
44
|
Chris@16
|
45 class reactive_socket_service_base
|
Chris@16
|
46 {
|
Chris@16
|
47 public:
|
Chris@16
|
48 // The native type of a socket.
|
Chris@16
|
49 typedef socket_type native_handle_type;
|
Chris@16
|
50
|
Chris@16
|
51 // The implementation type of the socket.
|
Chris@16
|
52 struct base_implementation_type
|
Chris@16
|
53 {
|
Chris@16
|
54 // The native socket representation.
|
Chris@16
|
55 socket_type socket_;
|
Chris@16
|
56
|
Chris@16
|
57 // The current state of the socket.
|
Chris@16
|
58 socket_ops::state_type state_;
|
Chris@16
|
59
|
Chris@16
|
60 // Per-descriptor data used by the reactor.
|
Chris@16
|
61 reactor::per_descriptor_data reactor_data_;
|
Chris@16
|
62 };
|
Chris@16
|
63
|
Chris@16
|
64 // Constructor.
|
Chris@16
|
65 BOOST_ASIO_DECL reactive_socket_service_base(
|
Chris@16
|
66 boost::asio::io_service& io_service);
|
Chris@16
|
67
|
Chris@16
|
68 // Destroy all user-defined handler objects owned by the service.
|
Chris@16
|
69 BOOST_ASIO_DECL void shutdown_service();
|
Chris@16
|
70
|
Chris@16
|
71 // Construct a new socket implementation.
|
Chris@16
|
72 BOOST_ASIO_DECL void construct(base_implementation_type& impl);
|
Chris@16
|
73
|
Chris@16
|
74 // Move-construct a new socket implementation.
|
Chris@16
|
75 BOOST_ASIO_DECL void base_move_construct(base_implementation_type& impl,
|
Chris@16
|
76 base_implementation_type& other_impl);
|
Chris@16
|
77
|
Chris@16
|
78 // Move-assign from another socket implementation.
|
Chris@16
|
79 BOOST_ASIO_DECL void base_move_assign(base_implementation_type& impl,
|
Chris@16
|
80 reactive_socket_service_base& other_service,
|
Chris@16
|
81 base_implementation_type& other_impl);
|
Chris@16
|
82
|
Chris@16
|
83 // Destroy a socket implementation.
|
Chris@16
|
84 BOOST_ASIO_DECL void destroy(base_implementation_type& impl);
|
Chris@16
|
85
|
Chris@16
|
86 // Determine whether the socket is open.
|
Chris@16
|
87 bool is_open(const base_implementation_type& impl) const
|
Chris@16
|
88 {
|
Chris@16
|
89 return impl.socket_ != invalid_socket;
|
Chris@16
|
90 }
|
Chris@16
|
91
|
Chris@16
|
92 // Destroy a socket implementation.
|
Chris@16
|
93 BOOST_ASIO_DECL boost::system::error_code close(
|
Chris@16
|
94 base_implementation_type& impl, boost::system::error_code& ec);
|
Chris@16
|
95
|
Chris@16
|
96 // Get the native socket representation.
|
Chris@16
|
97 native_handle_type native_handle(base_implementation_type& impl)
|
Chris@16
|
98 {
|
Chris@16
|
99 return impl.socket_;
|
Chris@16
|
100 }
|
Chris@16
|
101
|
Chris@16
|
102 // Cancel all operations associated with the socket.
|
Chris@16
|
103 BOOST_ASIO_DECL boost::system::error_code cancel(
|
Chris@16
|
104 base_implementation_type& impl, boost::system::error_code& ec);
|
Chris@16
|
105
|
Chris@16
|
106 // Determine whether the socket is at the out-of-band data mark.
|
Chris@16
|
107 bool at_mark(const base_implementation_type& impl,
|
Chris@16
|
108 boost::system::error_code& ec) const
|
Chris@16
|
109 {
|
Chris@16
|
110 return socket_ops::sockatmark(impl.socket_, ec);
|
Chris@16
|
111 }
|
Chris@16
|
112
|
Chris@16
|
113 // Determine the number of bytes available for reading.
|
Chris@16
|
114 std::size_t available(const base_implementation_type& impl,
|
Chris@16
|
115 boost::system::error_code& ec) const
|
Chris@16
|
116 {
|
Chris@16
|
117 return socket_ops::available(impl.socket_, ec);
|
Chris@16
|
118 }
|
Chris@16
|
119
|
Chris@16
|
120 // Place the socket into the state where it will listen for new connections.
|
Chris@16
|
121 boost::system::error_code listen(base_implementation_type& impl,
|
Chris@16
|
122 int backlog, boost::system::error_code& ec)
|
Chris@16
|
123 {
|
Chris@16
|
124 socket_ops::listen(impl.socket_, backlog, ec);
|
Chris@16
|
125 return ec;
|
Chris@16
|
126 }
|
Chris@16
|
127
|
Chris@16
|
128 // Perform an IO control command on the socket.
|
Chris@16
|
129 template <typename IO_Control_Command>
|
Chris@16
|
130 boost::system::error_code io_control(base_implementation_type& impl,
|
Chris@16
|
131 IO_Control_Command& command, boost::system::error_code& ec)
|
Chris@16
|
132 {
|
Chris@16
|
133 socket_ops::ioctl(impl.socket_, impl.state_, command.name(),
|
Chris@16
|
134 static_cast<ioctl_arg_type*>(command.data()), ec);
|
Chris@16
|
135 return ec;
|
Chris@16
|
136 }
|
Chris@16
|
137
|
Chris@16
|
138 // Gets the non-blocking mode of the socket.
|
Chris@16
|
139 bool non_blocking(const base_implementation_type& impl) const
|
Chris@16
|
140 {
|
Chris@16
|
141 return (impl.state_ & socket_ops::user_set_non_blocking) != 0;
|
Chris@16
|
142 }
|
Chris@16
|
143
|
Chris@16
|
144 // Sets the non-blocking mode of the socket.
|
Chris@16
|
145 boost::system::error_code non_blocking(base_implementation_type& impl,
|
Chris@16
|
146 bool mode, boost::system::error_code& ec)
|
Chris@16
|
147 {
|
Chris@16
|
148 socket_ops::set_user_non_blocking(impl.socket_, impl.state_, mode, ec);
|
Chris@16
|
149 return ec;
|
Chris@16
|
150 }
|
Chris@16
|
151
|
Chris@16
|
152 // Gets the non-blocking mode of the native socket implementation.
|
Chris@16
|
153 bool native_non_blocking(const base_implementation_type& impl) const
|
Chris@16
|
154 {
|
Chris@16
|
155 return (impl.state_ & socket_ops::internal_non_blocking) != 0;
|
Chris@16
|
156 }
|
Chris@16
|
157
|
Chris@16
|
158 // Sets the non-blocking mode of the native socket implementation.
|
Chris@16
|
159 boost::system::error_code native_non_blocking(base_implementation_type& impl,
|
Chris@16
|
160 bool mode, boost::system::error_code& ec)
|
Chris@16
|
161 {
|
Chris@16
|
162 socket_ops::set_internal_non_blocking(impl.socket_, impl.state_, mode, ec);
|
Chris@16
|
163 return ec;
|
Chris@16
|
164 }
|
Chris@16
|
165
|
Chris@16
|
166 // Disable sends or receives on the socket.
|
Chris@16
|
167 boost::system::error_code shutdown(base_implementation_type& impl,
|
Chris@16
|
168 socket_base::shutdown_type what, boost::system::error_code& ec)
|
Chris@16
|
169 {
|
Chris@16
|
170 socket_ops::shutdown(impl.socket_, what, ec);
|
Chris@16
|
171 return ec;
|
Chris@16
|
172 }
|
Chris@16
|
173
|
Chris@16
|
174 // Send the given data to the peer.
|
Chris@16
|
175 template <typename ConstBufferSequence>
|
Chris@16
|
176 size_t send(base_implementation_type& impl,
|
Chris@16
|
177 const ConstBufferSequence& buffers,
|
Chris@16
|
178 socket_base::message_flags flags, boost::system::error_code& ec)
|
Chris@16
|
179 {
|
Chris@16
|
180 buffer_sequence_adapter<boost::asio::const_buffer,
|
Chris@16
|
181 ConstBufferSequence> bufs(buffers);
|
Chris@16
|
182
|
Chris@16
|
183 return socket_ops::sync_send(impl.socket_, impl.state_,
|
Chris@16
|
184 bufs.buffers(), bufs.count(), flags, bufs.all_empty(), ec);
|
Chris@16
|
185 }
|
Chris@16
|
186
|
Chris@16
|
187 // Wait until data can be sent without blocking.
|
Chris@16
|
188 size_t send(base_implementation_type& impl, const null_buffers&,
|
Chris@16
|
189 socket_base::message_flags, boost::system::error_code& ec)
|
Chris@16
|
190 {
|
Chris@16
|
191 // Wait for socket to become ready.
|
Chris@16
|
192 socket_ops::poll_write(impl.socket_, impl.state_, ec);
|
Chris@16
|
193
|
Chris@16
|
194 return 0;
|
Chris@16
|
195 }
|
Chris@16
|
196
|
Chris@16
|
197 // Start an asynchronous send. The data being sent must be valid for the
|
Chris@16
|
198 // lifetime of the asynchronous operation.
|
Chris@16
|
199 template <typename ConstBufferSequence, typename Handler>
|
Chris@16
|
200 void async_send(base_implementation_type& impl,
|
Chris@16
|
201 const ConstBufferSequence& buffers,
|
Chris@16
|
202 socket_base::message_flags flags, Handler& handler)
|
Chris@16
|
203 {
|
Chris@16
|
204 bool is_continuation =
|
Chris@16
|
205 boost_asio_handler_cont_helpers::is_continuation(handler);
|
Chris@16
|
206
|
Chris@16
|
207 // Allocate and construct an operation to wrap the handler.
|
Chris@16
|
208 typedef reactive_socket_send_op<ConstBufferSequence, Handler> op;
|
Chris@16
|
209 typename op::ptr p = { boost::asio::detail::addressof(handler),
|
Chris@16
|
210 boost_asio_handler_alloc_helpers::allocate(
|
Chris@16
|
211 sizeof(op), handler), 0 };
|
Chris@16
|
212 p.p = new (p.v) op(impl.socket_, buffers, flags, handler);
|
Chris@16
|
213
|
Chris@16
|
214 BOOST_ASIO_HANDLER_CREATION((p.p, "socket", &impl, "async_send"));
|
Chris@16
|
215
|
Chris@16
|
216 start_op(impl, reactor::write_op, p.p, is_continuation, true,
|
Chris@16
|
217 ((impl.state_ & socket_ops::stream_oriented)
|
Chris@16
|
218 && buffer_sequence_adapter<boost::asio::const_buffer,
|
Chris@16
|
219 ConstBufferSequence>::all_empty(buffers)));
|
Chris@16
|
220 p.v = p.p = 0;
|
Chris@16
|
221 }
|
Chris@16
|
222
|
Chris@16
|
223 // Start an asynchronous wait until data can be sent without blocking.
|
Chris@16
|
224 template <typename Handler>
|
Chris@16
|
225 void async_send(base_implementation_type& impl, const null_buffers&,
|
Chris@16
|
226 socket_base::message_flags, Handler& handler)
|
Chris@16
|
227 {
|
Chris@16
|
228 bool is_continuation =
|
Chris@16
|
229 boost_asio_handler_cont_helpers::is_continuation(handler);
|
Chris@16
|
230
|
Chris@16
|
231 // Allocate and construct an operation to wrap the handler.
|
Chris@16
|
232 typedef reactive_null_buffers_op<Handler> op;
|
Chris@16
|
233 typename op::ptr p = { boost::asio::detail::addressof(handler),
|
Chris@16
|
234 boost_asio_handler_alloc_helpers::allocate(
|
Chris@16
|
235 sizeof(op), handler), 0 };
|
Chris@16
|
236 p.p = new (p.v) op(handler);
|
Chris@16
|
237
|
Chris@16
|
238 BOOST_ASIO_HANDLER_CREATION((p.p, "socket",
|
Chris@16
|
239 &impl, "async_send(null_buffers)"));
|
Chris@16
|
240
|
Chris@16
|
241 start_op(impl, reactor::write_op, p.p, is_continuation, false, false);
|
Chris@16
|
242 p.v = p.p = 0;
|
Chris@16
|
243 }
|
Chris@16
|
244
|
Chris@16
|
245 // Receive some data from the peer. Returns the number of bytes received.
|
Chris@16
|
246 template <typename MutableBufferSequence>
|
Chris@16
|
247 size_t receive(base_implementation_type& impl,
|
Chris@16
|
248 const MutableBufferSequence& buffers,
|
Chris@16
|
249 socket_base::message_flags flags, boost::system::error_code& ec)
|
Chris@16
|
250 {
|
Chris@16
|
251 buffer_sequence_adapter<boost::asio::mutable_buffer,
|
Chris@16
|
252 MutableBufferSequence> bufs(buffers);
|
Chris@16
|
253
|
Chris@16
|
254 return socket_ops::sync_recv(impl.socket_, impl.state_,
|
Chris@16
|
255 bufs.buffers(), bufs.count(), flags, bufs.all_empty(), ec);
|
Chris@16
|
256 }
|
Chris@16
|
257
|
Chris@16
|
258 // Wait until data can be received without blocking.
|
Chris@16
|
259 size_t receive(base_implementation_type& impl, const null_buffers&,
|
Chris@16
|
260 socket_base::message_flags, boost::system::error_code& ec)
|
Chris@16
|
261 {
|
Chris@16
|
262 // Wait for socket to become ready.
|
Chris@16
|
263 socket_ops::poll_read(impl.socket_, impl.state_, ec);
|
Chris@16
|
264
|
Chris@16
|
265 return 0;
|
Chris@16
|
266 }
|
Chris@16
|
267
|
Chris@16
|
268 // Start an asynchronous receive. The buffer for the data being received
|
Chris@16
|
269 // must be valid for the lifetime of the asynchronous operation.
|
Chris@16
|
270 template <typename MutableBufferSequence, typename Handler>
|
Chris@16
|
271 void async_receive(base_implementation_type& impl,
|
Chris@16
|
272 const MutableBufferSequence& buffers,
|
Chris@16
|
273 socket_base::message_flags flags, Handler& handler)
|
Chris@16
|
274 {
|
Chris@16
|
275 bool is_continuation =
|
Chris@16
|
276 boost_asio_handler_cont_helpers::is_continuation(handler);
|
Chris@16
|
277
|
Chris@16
|
278 // Allocate and construct an operation to wrap the handler.
|
Chris@16
|
279 typedef reactive_socket_recv_op<MutableBufferSequence, Handler> op;
|
Chris@16
|
280 typename op::ptr p = { boost::asio::detail::addressof(handler),
|
Chris@16
|
281 boost_asio_handler_alloc_helpers::allocate(
|
Chris@16
|
282 sizeof(op), handler), 0 };
|
Chris@16
|
283 p.p = new (p.v) op(impl.socket_, impl.state_, buffers, flags, handler);
|
Chris@16
|
284
|
Chris@16
|
285 BOOST_ASIO_HANDLER_CREATION((p.p, "socket", &impl, "async_receive"));
|
Chris@16
|
286
|
Chris@16
|
287 start_op(impl,
|
Chris@16
|
288 (flags & socket_base::message_out_of_band)
|
Chris@16
|
289 ? reactor::except_op : reactor::read_op,
|
Chris@16
|
290 p.p, is_continuation,
|
Chris@16
|
291 (flags & socket_base::message_out_of_band) == 0,
|
Chris@16
|
292 ((impl.state_ & socket_ops::stream_oriented)
|
Chris@16
|
293 && buffer_sequence_adapter<boost::asio::mutable_buffer,
|
Chris@16
|
294 MutableBufferSequence>::all_empty(buffers)));
|
Chris@16
|
295 p.v = p.p = 0;
|
Chris@16
|
296 }
|
Chris@16
|
297
|
Chris@16
|
298 // Wait until data can be received without blocking.
|
Chris@16
|
299 template <typename Handler>
|
Chris@16
|
300 void async_receive(base_implementation_type& impl, const null_buffers&,
|
Chris@16
|
301 socket_base::message_flags flags, Handler& handler)
|
Chris@16
|
302 {
|
Chris@16
|
303 bool is_continuation =
|
Chris@16
|
304 boost_asio_handler_cont_helpers::is_continuation(handler);
|
Chris@16
|
305
|
Chris@16
|
306 // Allocate and construct an operation to wrap the handler.
|
Chris@16
|
307 typedef reactive_null_buffers_op<Handler> op;
|
Chris@16
|
308 typename op::ptr p = { boost::asio::detail::addressof(handler),
|
Chris@16
|
309 boost_asio_handler_alloc_helpers::allocate(
|
Chris@16
|
310 sizeof(op), handler), 0 };
|
Chris@16
|
311 p.p = new (p.v) op(handler);
|
Chris@16
|
312
|
Chris@16
|
313 BOOST_ASIO_HANDLER_CREATION((p.p, "socket",
|
Chris@16
|
314 &impl, "async_receive(null_buffers)"));
|
Chris@16
|
315
|
Chris@16
|
316 start_op(impl,
|
Chris@16
|
317 (flags & socket_base::message_out_of_band)
|
Chris@16
|
318 ? reactor::except_op : reactor::read_op,
|
Chris@16
|
319 p.p, is_continuation, false, false);
|
Chris@16
|
320 p.v = p.p = 0;
|
Chris@16
|
321 }
|
Chris@16
|
322
|
Chris@16
|
323 // Receive some data with associated flags. Returns the number of bytes
|
Chris@16
|
324 // received.
|
Chris@16
|
325 template <typename MutableBufferSequence>
|
Chris@16
|
326 size_t receive_with_flags(base_implementation_type& impl,
|
Chris@16
|
327 const MutableBufferSequence& buffers,
|
Chris@16
|
328 socket_base::message_flags in_flags,
|
Chris@16
|
329 socket_base::message_flags& out_flags, boost::system::error_code& ec)
|
Chris@16
|
330 {
|
Chris@16
|
331 buffer_sequence_adapter<boost::asio::mutable_buffer,
|
Chris@16
|
332 MutableBufferSequence> bufs(buffers);
|
Chris@16
|
333
|
Chris@16
|
334 return socket_ops::sync_recvmsg(impl.socket_, impl.state_,
|
Chris@16
|
335 bufs.buffers(), bufs.count(), in_flags, out_flags, ec);
|
Chris@16
|
336 }
|
Chris@16
|
337
|
Chris@16
|
338 // Wait until data can be received without blocking.
|
Chris@16
|
339 size_t receive_with_flags(base_implementation_type& impl,
|
Chris@16
|
340 const null_buffers&, socket_base::message_flags,
|
Chris@16
|
341 socket_base::message_flags& out_flags, boost::system::error_code& ec)
|
Chris@16
|
342 {
|
Chris@16
|
343 // Wait for socket to become ready.
|
Chris@16
|
344 socket_ops::poll_read(impl.socket_, impl.state_, ec);
|
Chris@16
|
345
|
Chris@16
|
346 // Clear out_flags, since we cannot give it any other sensible value when
|
Chris@16
|
347 // performing a null_buffers operation.
|
Chris@16
|
348 out_flags = 0;
|
Chris@16
|
349
|
Chris@16
|
350 return 0;
|
Chris@16
|
351 }
|
Chris@16
|
352
|
Chris@16
|
353 // Start an asynchronous receive. The buffer for the data being received
|
Chris@16
|
354 // must be valid for the lifetime of the asynchronous operation.
|
Chris@16
|
355 template <typename MutableBufferSequence, typename Handler>
|
Chris@16
|
356 void async_receive_with_flags(base_implementation_type& impl,
|
Chris@16
|
357 const MutableBufferSequence& buffers, socket_base::message_flags in_flags,
|
Chris@16
|
358 socket_base::message_flags& out_flags, Handler& handler)
|
Chris@16
|
359 {
|
Chris@16
|
360 bool is_continuation =
|
Chris@16
|
361 boost_asio_handler_cont_helpers::is_continuation(handler);
|
Chris@16
|
362
|
Chris@16
|
363 // Allocate and construct an operation to wrap the handler.
|
Chris@16
|
364 typedef reactive_socket_recvmsg_op<MutableBufferSequence, Handler> op;
|
Chris@16
|
365 typename op::ptr p = { boost::asio::detail::addressof(handler),
|
Chris@16
|
366 boost_asio_handler_alloc_helpers::allocate(
|
Chris@16
|
367 sizeof(op), handler), 0 };
|
Chris@16
|
368 p.p = new (p.v) op(impl.socket_, buffers, in_flags, out_flags, handler);
|
Chris@16
|
369
|
Chris@16
|
370 BOOST_ASIO_HANDLER_CREATION((p.p, "socket",
|
Chris@16
|
371 &impl, "async_receive_with_flags"));
|
Chris@16
|
372
|
Chris@16
|
373 start_op(impl,
|
Chris@16
|
374 (in_flags & socket_base::message_out_of_band)
|
Chris@16
|
375 ? reactor::except_op : reactor::read_op,
|
Chris@16
|
376 p.p, is_continuation,
|
Chris@16
|
377 (in_flags & socket_base::message_out_of_band) == 0, false);
|
Chris@16
|
378 p.v = p.p = 0;
|
Chris@16
|
379 }
|
Chris@16
|
380
|
Chris@16
|
381 // Wait until data can be received without blocking.
|
Chris@16
|
382 template <typename Handler>
|
Chris@16
|
383 void async_receive_with_flags(base_implementation_type& impl,
|
Chris@16
|
384 const null_buffers&, socket_base::message_flags in_flags,
|
Chris@16
|
385 socket_base::message_flags& out_flags, Handler& handler)
|
Chris@16
|
386 {
|
Chris@16
|
387 bool is_continuation =
|
Chris@16
|
388 boost_asio_handler_cont_helpers::is_continuation(handler);
|
Chris@16
|
389
|
Chris@16
|
390 // Allocate and construct an operation to wrap the handler.
|
Chris@16
|
391 typedef reactive_null_buffers_op<Handler> op;
|
Chris@16
|
392 typename op::ptr p = { boost::asio::detail::addressof(handler),
|
Chris@16
|
393 boost_asio_handler_alloc_helpers::allocate(
|
Chris@16
|
394 sizeof(op), handler), 0 };
|
Chris@16
|
395 p.p = new (p.v) op(handler);
|
Chris@16
|
396
|
Chris@16
|
397 BOOST_ASIO_HANDLER_CREATION((p.p, "socket", &impl,
|
Chris@16
|
398 "async_receive_with_flags(null_buffers)"));
|
Chris@16
|
399
|
Chris@16
|
400 // Clear out_flags, since we cannot give it any other sensible value when
|
Chris@16
|
401 // performing a null_buffers operation.
|
Chris@16
|
402 out_flags = 0;
|
Chris@16
|
403
|
Chris@16
|
404 start_op(impl,
|
Chris@16
|
405 (in_flags & socket_base::message_out_of_band)
|
Chris@16
|
406 ? reactor::except_op : reactor::read_op,
|
Chris@16
|
407 p.p, is_continuation, false, false);
|
Chris@16
|
408 p.v = p.p = 0;
|
Chris@16
|
409 }
|
Chris@16
|
410
|
Chris@16
|
411 protected:
|
Chris@16
|
412 // Open a new socket implementation.
|
Chris@16
|
413 BOOST_ASIO_DECL boost::system::error_code do_open(
|
Chris@16
|
414 base_implementation_type& impl, int af,
|
Chris@16
|
415 int type, int protocol, boost::system::error_code& ec);
|
Chris@16
|
416
|
Chris@16
|
417 // Assign a native socket to a socket implementation.
|
Chris@16
|
418 BOOST_ASIO_DECL boost::system::error_code do_assign(
|
Chris@16
|
419 base_implementation_type& impl, int type,
|
Chris@16
|
420 const native_handle_type& native_socket, boost::system::error_code& ec);
|
Chris@16
|
421
|
Chris@16
|
422 // Start the asynchronous read or write operation.
|
Chris@16
|
423 BOOST_ASIO_DECL void start_op(base_implementation_type& impl, int op_type,
|
Chris@16
|
424 reactor_op* op, bool is_continuation, bool is_non_blocking, bool noop);
|
Chris@16
|
425
|
Chris@16
|
426 // Start the asynchronous accept operation.
|
Chris@16
|
427 BOOST_ASIO_DECL void start_accept_op(base_implementation_type& impl,
|
Chris@16
|
428 reactor_op* op, bool is_continuation, bool peer_is_open);
|
Chris@16
|
429
|
Chris@16
|
430 // Start the asynchronous connect operation.
|
Chris@16
|
431 BOOST_ASIO_DECL void start_connect_op(base_implementation_type& impl,
|
Chris@16
|
432 reactor_op* op, bool is_continuation,
|
Chris@16
|
433 const socket_addr_type* addr, size_t addrlen);
|
Chris@16
|
434
|
Chris@16
|
435 // The selector that performs event demultiplexing for the service.
|
Chris@16
|
436 reactor& reactor_;
|
Chris@16
|
437 };
|
Chris@16
|
438
|
Chris@16
|
439 } // namespace detail
|
Chris@16
|
440 } // namespace asio
|
Chris@16
|
441 } // namespace boost
|
Chris@16
|
442
|
Chris@16
|
443 #include <boost/asio/detail/pop_options.hpp>
|
Chris@16
|
444
|
Chris@16
|
445 #if defined(BOOST_ASIO_HEADER_ONLY)
|
Chris@16
|
446 # include <boost/asio/detail/impl/reactive_socket_service_base.ipp>
|
Chris@16
|
447 #endif // defined(BOOST_ASIO_HEADER_ONLY)
|
Chris@16
|
448
|
Chris@16
|
449 #endif // !defined(BOOST_ASIO_HAS_IOCP)
|
Chris@16
|
450 // && !defined(BOOST_ASIO_WINDOWS_RUNTIME)
|
Chris@16
|
451
|
Chris@16
|
452 #endif // BOOST_ASIO_DETAIL_REACTIVE_SOCKET_SERVICE_BASE_HPP
|