11 #ifndef ASIO_DETAIL_REACTIVE_SOCKET_SERVICE_BASE_HPP 12 #define ASIO_DETAIL_REACTIVE_SOCKET_SERVICE_BASE_HPP 14 #if defined(_MSC_VER) && (_MSC_VER >= 1200) 16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) 18 #include "asio/detail/config.hpp" 20 #if !defined(ASIO_HAS_IOCP) \ 21 && !defined(ASIO_WINDOWS_RUNTIME) 23 #include "asio/buffer.hpp" 24 #include "asio/error.hpp" 25 #include "asio/execution_context.hpp" 26 #include "asio/socket_base.hpp" 27 #include "asio/detail/buffer_sequence_adapter.hpp" 28 #include "asio/detail/memory.hpp" 29 #include "asio/detail/reactive_null_buffers_op.hpp" 30 #include "asio/detail/reactive_socket_recv_op.hpp" 31 #include "asio/detail/reactive_socket_recvmsg_op.hpp" 32 #include "asio/detail/reactive_socket_send_op.hpp" 33 #include "asio/detail/reactive_wait_op.hpp" 34 #include "asio/detail/reactor.hpp" 35 #include "asio/detail/reactor_op.hpp" 36 #include "asio/detail/socket_holder.hpp" 37 #include "asio/detail/socket_ops.hpp" 38 #include "asio/detail/socket_types.hpp" 40 #include "asio/detail/push_options.hpp" 49 typedef socket_type native_handle_type;
58 socket_ops::state_type state_;
61 reactor::per_descriptor_data reactor_data_;
68 ASIO_DECL
void base_shutdown();
79 reactive_socket_service_base& other_service,
88 return impl.socket_ != invalid_socket;
96 ASIO_DECL socket_type release(
113 return socket_ops::sockatmark(impl.socket_, ec);
120 return socket_ops::available(impl.socket_, ec);
127 socket_ops::listen(impl.socket_, backlog, ec);
132 template <
typename IO_Control_Command>
136 socket_ops::ioctl(impl.socket_, impl.state_, command.name(),
137 static_cast<ioctl_arg_type*
>(command.data()), ec);
144 return (impl.state_ & socket_ops::user_set_non_blocking) != 0;
151 socket_ops::set_user_non_blocking(impl.socket_, impl.state_, mode, ec);
158 return (impl.state_ & socket_ops::internal_non_blocking) != 0;
165 socket_ops::set_internal_non_blocking(impl.socket_, impl.state_, mode, ec);
177 socket_ops::poll_read(impl.socket_, impl.state_, -1, ec);
180 socket_ops::poll_write(impl.socket_, impl.state_, -1, ec);
183 socket_ops::poll_error(impl.socket_, impl.state_, -1, ec);
186 ec = asio::error::invalid_argument;
195 template <
typename Handler,
typename IoExecutor>
199 bool is_continuation =
200 asio_handler_cont_helpers::is_continuation(handler);
204 typename op::ptr p = { asio::detail::addressof(handler),
205 op::ptr::allocate(handler), 0 };
206 p.p =
new (p.v) op(success_ec_, handler, io_ex);
208 ASIO_HANDLER_CREATION((reactor_.context(), *p.p,
"socket",
209 &impl, impl.socket_,
"async_wait"));
215 op_type = reactor::read_op;
218 op_type = reactor::write_op;
221 op_type = reactor::except_op;
224 p.p->ec_ = asio::error::invalid_argument;
225 reactor_.post_immediate_completion(p.p, is_continuation);
230 start_op(impl, op_type, p.p, is_continuation,
false,
false);
235 template <
typename ConstBufferSequence>
237 const ConstBufferSequence& buffers,
241 ConstBufferSequence> bufs_type;
243 if (bufs_type::is_single_buffer)
245 return socket_ops::sync_send1(impl.socket_,
246 impl.state_, bufs_type::first(buffers).data(),
247 bufs_type::first(buffers).size(), flags, ec);
251 bufs_type bufs(buffers);
252 return socket_ops::sync_send(impl.socket_, impl.state_,
253 bufs.buffers(), bufs.count(), flags, bufs.all_empty(), ec);
262 socket_ops::poll_write(impl.socket_, impl.state_, -1, ec);
269 template <
typename ConstBufferSequence,
typename Handler,
typename IoExecutor>
272 Handler& handler,
const IoExecutor& io_ex)
274 bool is_continuation =
275 asio_handler_cont_helpers::is_continuation(handler);
279 ConstBufferSequence, Handler, IoExecutor> op;
280 typename op::ptr p = { asio::detail::addressof(handler),
281 op::ptr::allocate(handler), 0 };
282 p.p =
new (p.v) op(success_ec_, impl.socket_,
283 impl.state_, buffers, flags, handler, io_ex);
285 ASIO_HANDLER_CREATION((reactor_.context(), *p.p,
"socket",
286 &impl, impl.socket_,
"async_send"));
288 start_op(impl, reactor::write_op, p.p, is_continuation,
true,
289 ((impl.state_ & socket_ops::stream_oriented)
291 ConstBufferSequence>::all_empty(buffers)));
296 template <
typename Handler,
typename IoExecutor>
300 bool is_continuation =
301 asio_handler_cont_helpers::is_continuation(handler);
305 typename op::ptr p = { asio::detail::addressof(handler),
306 op::ptr::allocate(handler), 0 };
307 p.p =
new (p.v) op(success_ec_, handler, io_ex);
309 ASIO_HANDLER_CREATION((reactor_.context(), *p.p,
"socket",
310 &impl, impl.socket_,
"async_send(null_buffers)"));
312 start_op(impl, reactor::write_op, p.p, is_continuation,
false,
false);
317 template <
typename MutableBufferSequence>
319 const MutableBufferSequence& buffers,
323 MutableBufferSequence> bufs_type;
325 if (bufs_type::is_single_buffer)
327 return socket_ops::sync_recv1(impl.socket_,
328 impl.state_, bufs_type::first(buffers).data(),
329 bufs_type::first(buffers).size(), flags, ec);
333 bufs_type bufs(buffers);
334 return socket_ops::sync_recv(impl.socket_, impl.state_,
335 bufs.buffers(), bufs.count(), flags, bufs.all_empty(), ec);
344 socket_ops::poll_read(impl.socket_, impl.state_, -1, ec);
351 template <
typename MutableBufferSequence,
352 typename Handler,
typename IoExecutor>
355 Handler& handler,
const IoExecutor& io_ex)
357 bool is_continuation =
358 asio_handler_cont_helpers::is_continuation(handler);
362 MutableBufferSequence, Handler, IoExecutor> op;
363 typename op::ptr p = { asio::detail::addressof(handler),
364 op::ptr::allocate(handler), 0 };
365 p.p =
new (p.v) op(success_ec_, impl.socket_,
366 impl.state_, buffers, flags, handler, io_ex);
368 ASIO_HANDLER_CREATION((reactor_.context(), *p.p,
"socket",
369 &impl, impl.socket_,
"async_receive"));
372 (flags & socket_base::message_out_of_band)
373 ? reactor::except_op : reactor::read_op,
374 p.p, is_continuation,
375 (flags & socket_base::message_out_of_band) == 0,
376 ((impl.state_ & socket_ops::stream_oriented)
378 MutableBufferSequence>::all_empty(buffers)));
383 template <
typename Handler,
typename IoExecutor>
386 Handler& handler,
const IoExecutor& io_ex)
388 bool is_continuation =
389 asio_handler_cont_helpers::is_continuation(handler);
393 typename op::ptr p = { asio::detail::addressof(handler),
394 op::ptr::allocate(handler), 0 };
395 p.p =
new (p.v) op(success_ec_, handler, io_ex);
397 ASIO_HANDLER_CREATION((reactor_.context(), *p.p,
"socket",
398 &impl, impl.socket_,
"async_receive(null_buffers)"));
401 (flags & socket_base::message_out_of_band)
402 ? reactor::except_op : reactor::read_op,
403 p.p, is_continuation,
false,
false);
409 template <
typename MutableBufferSequence>
411 const MutableBufferSequence& buffers,
416 MutableBufferSequence> bufs(buffers);
418 return socket_ops::sync_recvmsg(impl.socket_, impl.state_,
419 bufs.buffers(), bufs.count(), in_flags, out_flags, ec);
428 socket_ops::poll_read(impl.socket_, impl.state_, -1, ec);
439 template <
typename MutableBufferSequence,
440 typename Handler,
typename IoExecutor>
444 const IoExecutor& io_ex)
446 bool is_continuation =
447 asio_handler_cont_helpers::is_continuation(handler);
451 MutableBufferSequence, Handler, IoExecutor> op;
452 typename op::ptr p = { asio::detail::addressof(handler),
453 op::ptr::allocate(handler), 0 };
454 p.p =
new (p.v) op(success_ec_, impl.socket_,
455 buffers, in_flags, out_flags, handler, io_ex);
457 ASIO_HANDLER_CREATION((reactor_.context(), *p.p,
"socket",
458 &impl, impl.socket_,
"async_receive_with_flags"));
461 (in_flags & socket_base::message_out_of_band)
462 ? reactor::except_op : reactor::read_op,
463 p.p, is_continuation,
464 (in_flags & socket_base::message_out_of_band) == 0,
false);
469 template <
typename Handler,
typename IoExecutor>
473 const IoExecutor& io_ex)
475 bool is_continuation =
476 asio_handler_cont_helpers::is_continuation(handler);
480 typename op::ptr p = { asio::detail::addressof(handler),
481 op::ptr::allocate(handler), 0 };
482 p.p =
new (p.v) op(success_ec_, handler, io_ex);
484 ASIO_HANDLER_CREATION((reactor_.context(), *p.p,
"socket",
485 &impl, impl.socket_,
"async_receive_with_flags(null_buffers)"));
492 (in_flags & socket_base::message_out_of_band)
493 ? reactor::except_op : reactor::read_op,
494 p.p, is_continuation,
false,
false);
511 reactor_op* op,
bool is_continuation,
bool is_non_blocking,
bool noop);
515 reactor_op* op,
bool is_continuation,
bool peer_is_open);
520 const socket_addr_type* addr,
size_t addrlen);
532 #include "asio/detail/pop_options.hpp" 534 #if defined(ASIO_HEADER_ONLY) 535 # include "asio/detail/impl/reactive_socket_service_base.ipp" 536 #endif // defined(ASIO_HEADER_ONLY) 538 #endif // !defined(ASIO_HAS_IOCP) 541 #endif // ASIO_DETAIL_REACTIVE_SOCKET_SERVICE_BASE_HPP int message_flags
Bitmask type for flags that can be passed to send and receive operations.
Definition: socket_base.hpp:53
Holds a buffer that cannot be modified.
Definition: buffer.hpp:226
wait_type
Wait types.
Definition: socket_base.hpp:82
Definition: reactive_socket_service_base.hpp:52
Definition: reactive_socket_send_op.hpp:99
Definition: reactive_wait_op.hpp:33
A context for function object execution.
Definition: execution_context.hpp:105
Wait for a socket to have error conditions pending.
Definition: socket_base.hpp:91
Definition: reactive_socket_recvmsg_op.hpp:79
Definition: buffer_sequence_adapter.hpp:103
Holds a buffer that can be modified.
Definition: buffer.hpp:92
Class to represent an error code value.
Definition: error_code.hpp:80
Wait for a socket to become ready to write.
Definition: socket_base.hpp:88
Definition: reactive_null_buffers_op.hpp:33
Wait for a socket to become ready to read.
Definition: socket_base.hpp:85
(Deprecated: Use the socket/descriptor wait() and async_wait() member functions.) An implementation o...
Definition: buffer.hpp:354
Definition: reactor_op.hpp:26
Definition: reactive_socket_service_base.hpp:45
Definition: any_io_executor.hpp:28
Definition: reactive_socket_recv_op.hpp:96