annotate DEPENDENCIES/generic/include/boost/asio/detail/reactive_descriptor_service.hpp @ 133:4acb5d8d80b6 tip

Don't fail environmental check if README.md exists (but .txt and no-suffix don't)
author Chris Cannam
date Tue, 30 Jul 2019 12:25:44 +0100
parents c530137014c0
children
rev   line source
Chris@16 1 //
Chris@16 2 // detail/reactive_descriptor_service.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_DESCRIPTOR_SERVICE_HPP
Chris@16 12 #define BOOST_ASIO_DETAIL_REACTIVE_DESCRIPTOR_SERVICE_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_WINDOWS) \
Chris@16 21 && !defined(BOOST_ASIO_WINDOWS_RUNTIME) \
Chris@16 22 && !defined(__CYGWIN__)
Chris@16 23
Chris@16 24 #include <boost/asio/buffer.hpp>
Chris@16 25 #include <boost/asio/io_service.hpp>
Chris@16 26 #include <boost/asio/detail/addressof.hpp>
Chris@16 27 #include <boost/asio/detail/bind_handler.hpp>
Chris@16 28 #include <boost/asio/detail/buffer_sequence_adapter.hpp>
Chris@16 29 #include <boost/asio/detail/descriptor_ops.hpp>
Chris@16 30 #include <boost/asio/detail/descriptor_read_op.hpp>
Chris@16 31 #include <boost/asio/detail/descriptor_write_op.hpp>
Chris@16 32 #include <boost/asio/detail/fenced_block.hpp>
Chris@16 33 #include <boost/asio/detail/noncopyable.hpp>
Chris@16 34 #include <boost/asio/detail/reactive_null_buffers_op.hpp>
Chris@16 35 #include <boost/asio/detail/reactor.hpp>
Chris@16 36
Chris@16 37 #include <boost/asio/detail/push_options.hpp>
Chris@16 38
Chris@16 39 namespace boost {
Chris@16 40 namespace asio {
Chris@16 41 namespace detail {
Chris@16 42
Chris@16 43 class reactive_descriptor_service
Chris@16 44 {
Chris@16 45 public:
Chris@16 46 // The native type of a descriptor.
Chris@16 47 typedef int native_handle_type;
Chris@16 48
Chris@16 49 // The implementation type of the descriptor.
Chris@16 50 class implementation_type
Chris@16 51 : private boost::asio::detail::noncopyable
Chris@16 52 {
Chris@16 53 public:
Chris@16 54 // Default constructor.
Chris@16 55 implementation_type()
Chris@16 56 : descriptor_(-1),
Chris@16 57 state_(0)
Chris@16 58 {
Chris@16 59 }
Chris@16 60
Chris@16 61 private:
Chris@16 62 // Only this service will have access to the internal values.
Chris@16 63 friend class reactive_descriptor_service;
Chris@16 64
Chris@16 65 // The native descriptor representation.
Chris@16 66 int descriptor_;
Chris@16 67
Chris@16 68 // The current state of the descriptor.
Chris@16 69 descriptor_ops::state_type state_;
Chris@16 70
Chris@16 71 // Per-descriptor data used by the reactor.
Chris@16 72 reactor::per_descriptor_data reactor_data_;
Chris@16 73 };
Chris@16 74
Chris@16 75 // Constructor.
Chris@16 76 BOOST_ASIO_DECL reactive_descriptor_service(
Chris@16 77 boost::asio::io_service& io_service);
Chris@16 78
Chris@16 79 // Destroy all user-defined handler objects owned by the service.
Chris@16 80 BOOST_ASIO_DECL void shutdown_service();
Chris@16 81
Chris@16 82 // Construct a new descriptor implementation.
Chris@16 83 BOOST_ASIO_DECL void construct(implementation_type& impl);
Chris@16 84
Chris@16 85 // Move-construct a new descriptor implementation.
Chris@16 86 BOOST_ASIO_DECL void move_construct(implementation_type& impl,
Chris@16 87 implementation_type& other_impl);
Chris@16 88
Chris@16 89 // Move-assign from another descriptor implementation.
Chris@16 90 BOOST_ASIO_DECL void move_assign(implementation_type& impl,
Chris@16 91 reactive_descriptor_service& other_service,
Chris@16 92 implementation_type& other_impl);
Chris@16 93
Chris@16 94 // Destroy a descriptor implementation.
Chris@16 95 BOOST_ASIO_DECL void destroy(implementation_type& impl);
Chris@16 96
Chris@16 97 // Assign a native descriptor to a descriptor implementation.
Chris@16 98 BOOST_ASIO_DECL boost::system::error_code assign(implementation_type& impl,
Chris@16 99 const native_handle_type& native_descriptor,
Chris@16 100 boost::system::error_code& ec);
Chris@16 101
Chris@16 102 // Determine whether the descriptor is open.
Chris@16 103 bool is_open(const implementation_type& impl) const
Chris@16 104 {
Chris@16 105 return impl.descriptor_ != -1;
Chris@16 106 }
Chris@16 107
Chris@16 108 // Destroy a descriptor implementation.
Chris@16 109 BOOST_ASIO_DECL boost::system::error_code close(implementation_type& impl,
Chris@16 110 boost::system::error_code& ec);
Chris@16 111
Chris@16 112 // Get the native descriptor representation.
Chris@16 113 native_handle_type native_handle(const implementation_type& impl) const
Chris@16 114 {
Chris@16 115 return impl.descriptor_;
Chris@16 116 }
Chris@16 117
Chris@16 118 // Release ownership of the native descriptor representation.
Chris@16 119 BOOST_ASIO_DECL native_handle_type release(implementation_type& impl);
Chris@16 120
Chris@16 121 // Cancel all operations associated with the descriptor.
Chris@16 122 BOOST_ASIO_DECL boost::system::error_code cancel(implementation_type& impl,
Chris@16 123 boost::system::error_code& ec);
Chris@16 124
Chris@16 125 // Perform an IO control command on the descriptor.
Chris@16 126 template <typename IO_Control_Command>
Chris@16 127 boost::system::error_code io_control(implementation_type& impl,
Chris@16 128 IO_Control_Command& command, boost::system::error_code& ec)
Chris@16 129 {
Chris@16 130 descriptor_ops::ioctl(impl.descriptor_, impl.state_,
Chris@16 131 command.name(), static_cast<ioctl_arg_type*>(command.data()), ec);
Chris@16 132 return ec;
Chris@16 133 }
Chris@16 134
Chris@16 135 // Gets the non-blocking mode of the descriptor.
Chris@16 136 bool non_blocking(const implementation_type& impl) const
Chris@16 137 {
Chris@16 138 return (impl.state_ & descriptor_ops::user_set_non_blocking) != 0;
Chris@16 139 }
Chris@16 140
Chris@16 141 // Sets the non-blocking mode of the descriptor.
Chris@16 142 boost::system::error_code non_blocking(implementation_type& impl,
Chris@16 143 bool mode, boost::system::error_code& ec)
Chris@16 144 {
Chris@16 145 descriptor_ops::set_user_non_blocking(
Chris@16 146 impl.descriptor_, impl.state_, mode, ec);
Chris@16 147 return ec;
Chris@16 148 }
Chris@16 149
Chris@16 150 // Gets the non-blocking mode of the native descriptor implementation.
Chris@16 151 bool native_non_blocking(const implementation_type& impl) const
Chris@16 152 {
Chris@16 153 return (impl.state_ & descriptor_ops::internal_non_blocking) != 0;
Chris@16 154 }
Chris@16 155
Chris@16 156 // Sets the non-blocking mode of the native descriptor implementation.
Chris@16 157 boost::system::error_code native_non_blocking(implementation_type& impl,
Chris@16 158 bool mode, boost::system::error_code& ec)
Chris@16 159 {
Chris@16 160 descriptor_ops::set_internal_non_blocking(
Chris@16 161 impl.descriptor_, impl.state_, mode, ec);
Chris@16 162 return ec;
Chris@16 163 }
Chris@16 164
Chris@16 165 // Write some data to the descriptor.
Chris@16 166 template <typename ConstBufferSequence>
Chris@16 167 size_t write_some(implementation_type& impl,
Chris@16 168 const ConstBufferSequence& buffers, boost::system::error_code& ec)
Chris@16 169 {
Chris@16 170 buffer_sequence_adapter<boost::asio::const_buffer,
Chris@16 171 ConstBufferSequence> bufs(buffers);
Chris@16 172
Chris@16 173 return descriptor_ops::sync_write(impl.descriptor_, impl.state_,
Chris@16 174 bufs.buffers(), bufs.count(), bufs.all_empty(), ec);
Chris@16 175 }
Chris@16 176
Chris@16 177 // Wait until data can be written without blocking.
Chris@16 178 size_t write_some(implementation_type& impl,
Chris@16 179 const null_buffers&, boost::system::error_code& ec)
Chris@16 180 {
Chris@16 181 // Wait for descriptor to become ready.
Chris@16 182 descriptor_ops::poll_write(impl.descriptor_, impl.state_, ec);
Chris@16 183
Chris@16 184 return 0;
Chris@16 185 }
Chris@16 186
Chris@16 187 // Start an asynchronous write. The data being sent must be valid for the
Chris@16 188 // lifetime of the asynchronous operation.
Chris@16 189 template <typename ConstBufferSequence, typename Handler>
Chris@16 190 void async_write_some(implementation_type& impl,
Chris@16 191 const ConstBufferSequence& buffers, Handler& handler)
Chris@16 192 {
Chris@16 193 bool is_continuation =
Chris@16 194 boost_asio_handler_cont_helpers::is_continuation(handler);
Chris@16 195
Chris@16 196 // Allocate and construct an operation to wrap the handler.
Chris@16 197 typedef descriptor_write_op<ConstBufferSequence, Handler> op;
Chris@16 198 typename op::ptr p = { boost::asio::detail::addressof(handler),
Chris@16 199 boost_asio_handler_alloc_helpers::allocate(
Chris@16 200 sizeof(op), handler), 0 };
Chris@16 201 p.p = new (p.v) op(impl.descriptor_, buffers, handler);
Chris@16 202
Chris@16 203 BOOST_ASIO_HANDLER_CREATION((p.p, "descriptor", &impl, "async_write_some"));
Chris@16 204
Chris@16 205 start_op(impl, reactor::write_op, p.p, is_continuation, true,
Chris@16 206 buffer_sequence_adapter<boost::asio::const_buffer,
Chris@16 207 ConstBufferSequence>::all_empty(buffers));
Chris@16 208 p.v = p.p = 0;
Chris@16 209 }
Chris@16 210
Chris@16 211 // Start an asynchronous wait until data can be written without blocking.
Chris@16 212 template <typename Handler>
Chris@16 213 void async_write_some(implementation_type& impl,
Chris@16 214 const null_buffers&, Handler& handler)
Chris@16 215 {
Chris@16 216 bool is_continuation =
Chris@16 217 boost_asio_handler_cont_helpers::is_continuation(handler);
Chris@16 218
Chris@16 219 // Allocate and construct an operation to wrap the handler.
Chris@16 220 typedef reactive_null_buffers_op<Handler> op;
Chris@16 221 typename op::ptr p = { boost::asio::detail::addressof(handler),
Chris@16 222 boost_asio_handler_alloc_helpers::allocate(
Chris@16 223 sizeof(op), handler), 0 };
Chris@16 224 p.p = new (p.v) op(handler);
Chris@16 225
Chris@16 226 BOOST_ASIO_HANDLER_CREATION((p.p, "descriptor",
Chris@16 227 &impl, "async_write_some(null_buffers)"));
Chris@16 228
Chris@16 229 start_op(impl, reactor::write_op, p.p, is_continuation, false, false);
Chris@16 230 p.v = p.p = 0;
Chris@16 231 }
Chris@16 232
Chris@16 233 // Read some data from the stream. Returns the number of bytes read.
Chris@16 234 template <typename MutableBufferSequence>
Chris@16 235 size_t read_some(implementation_type& impl,
Chris@16 236 const MutableBufferSequence& buffers, boost::system::error_code& ec)
Chris@16 237 {
Chris@16 238 buffer_sequence_adapter<boost::asio::mutable_buffer,
Chris@16 239 MutableBufferSequence> bufs(buffers);
Chris@16 240
Chris@16 241 return descriptor_ops::sync_read(impl.descriptor_, impl.state_,
Chris@16 242 bufs.buffers(), bufs.count(), bufs.all_empty(), ec);
Chris@16 243 }
Chris@16 244
Chris@16 245 // Wait until data can be read without blocking.
Chris@16 246 size_t read_some(implementation_type& impl,
Chris@16 247 const null_buffers&, boost::system::error_code& ec)
Chris@16 248 {
Chris@16 249 // Wait for descriptor to become ready.
Chris@16 250 descriptor_ops::poll_read(impl.descriptor_, impl.state_, ec);
Chris@16 251
Chris@16 252 return 0;
Chris@16 253 }
Chris@16 254
Chris@16 255 // Start an asynchronous read. The buffer for the data being read must be
Chris@16 256 // valid for the lifetime of the asynchronous operation.
Chris@16 257 template <typename MutableBufferSequence, typename Handler>
Chris@16 258 void async_read_some(implementation_type& impl,
Chris@16 259 const MutableBufferSequence& buffers, Handler& handler)
Chris@16 260 {
Chris@16 261 bool is_continuation =
Chris@16 262 boost_asio_handler_cont_helpers::is_continuation(handler);
Chris@16 263
Chris@16 264 // Allocate and construct an operation to wrap the handler.
Chris@16 265 typedef descriptor_read_op<MutableBufferSequence, Handler> op;
Chris@16 266 typename op::ptr p = { boost::asio::detail::addressof(handler),
Chris@16 267 boost_asio_handler_alloc_helpers::allocate(
Chris@16 268 sizeof(op), handler), 0 };
Chris@16 269 p.p = new (p.v) op(impl.descriptor_, buffers, handler);
Chris@16 270
Chris@16 271 BOOST_ASIO_HANDLER_CREATION((p.p, "descriptor", &impl, "async_read_some"));
Chris@16 272
Chris@16 273 start_op(impl, reactor::read_op, p.p, is_continuation, true,
Chris@16 274 buffer_sequence_adapter<boost::asio::mutable_buffer,
Chris@16 275 MutableBufferSequence>::all_empty(buffers));
Chris@16 276 p.v = p.p = 0;
Chris@16 277 }
Chris@16 278
Chris@16 279 // Wait until data can be read without blocking.
Chris@16 280 template <typename Handler>
Chris@16 281 void async_read_some(implementation_type& impl,
Chris@16 282 const null_buffers&, Handler& handler)
Chris@16 283 {
Chris@16 284 bool is_continuation =
Chris@16 285 boost_asio_handler_cont_helpers::is_continuation(handler);
Chris@16 286
Chris@16 287 // Allocate and construct an operation to wrap the handler.
Chris@16 288 typedef reactive_null_buffers_op<Handler> op;
Chris@16 289 typename op::ptr p = { boost::asio::detail::addressof(handler),
Chris@16 290 boost_asio_handler_alloc_helpers::allocate(
Chris@16 291 sizeof(op), handler), 0 };
Chris@16 292 p.p = new (p.v) op(handler);
Chris@16 293
Chris@16 294 BOOST_ASIO_HANDLER_CREATION((p.p, "descriptor",
Chris@16 295 &impl, "async_read_some(null_buffers)"));
Chris@16 296
Chris@16 297 start_op(impl, reactor::read_op, p.p, is_continuation, false, false);
Chris@16 298 p.v = p.p = 0;
Chris@16 299 }
Chris@16 300
Chris@16 301 private:
Chris@16 302 // Start the asynchronous operation.
Chris@16 303 BOOST_ASIO_DECL void start_op(implementation_type& impl, int op_type,
Chris@16 304 reactor_op* op, bool is_continuation, bool is_non_blocking, bool noop);
Chris@16 305
Chris@16 306 // The selector that performs event demultiplexing for the service.
Chris@16 307 reactor& reactor_;
Chris@16 308 };
Chris@16 309
Chris@16 310 } // namespace detail
Chris@16 311 } // namespace asio
Chris@16 312 } // namespace boost
Chris@16 313
Chris@16 314 #include <boost/asio/detail/pop_options.hpp>
Chris@16 315
Chris@16 316 #if defined(BOOST_ASIO_HEADER_ONLY)
Chris@16 317 # include <boost/asio/detail/impl/reactive_descriptor_service.ipp>
Chris@16 318 #endif // defined(BOOST_ASIO_HEADER_ONLY)
Chris@16 319
Chris@16 320 #endif // !defined(BOOST_ASIO_WINDOWS)
Chris@16 321 // && !defined(BOOST_ASIO_WINDOWS_RUNTIME)
Chris@16 322 // && !defined(__CYGWIN__)
Chris@16 323
Chris@16 324 #endif // BOOST_ASIO_DETAIL_REACTIVE_DESCRIPTOR_SERVICE_HPP