diff options
Diffstat (limited to '3rdParty/Boost/src/boost/asio/detail/reactive_socket_service_base.hpp')
-rw-r--r-- | 3rdParty/Boost/src/boost/asio/detail/reactive_socket_service_base.hpp | 145 |
1 files changed, 137 insertions, 8 deletions
diff --git a/3rdParty/Boost/src/boost/asio/detail/reactive_socket_service_base.hpp b/3rdParty/Boost/src/boost/asio/detail/reactive_socket_service_base.hpp index df87ddb..0180435 100644 --- a/3rdParty/Boost/src/boost/asio/detail/reactive_socket_service_base.hpp +++ b/3rdParty/Boost/src/boost/asio/detail/reactive_socket_service_base.hpp @@ -2,7 +2,7 @@ // detail/reactive_socket_service_base.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // -// Copyright (c) 2003-2011 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// Copyright (c) 2003-2012 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) @@ -27,6 +27,7 @@ #include <boost/asio/detail/buffer_sequence_adapter.hpp> #include <boost/asio/detail/reactive_null_buffers_op.hpp> #include <boost/asio/detail/reactive_socket_recv_op.hpp> +#include <boost/asio/detail/reactive_socket_recvmsg_op.hpp> #include <boost/asio/detail/reactive_socket_send_op.hpp> #include <boost/asio/detail/reactor.hpp> #include <boost/asio/detail/reactor_op.hpp> @@ -44,7 +45,7 @@ class reactive_socket_service_base { public: // The native type of a socket. - typedef socket_type native_type; + typedef socket_type native_handle_type; // The implementation type of the socket. struct base_implementation_type @@ -69,6 +70,15 @@ public: // Construct a new socket implementation. BOOST_ASIO_DECL void construct(base_implementation_type& impl); + // Move-construct a new socket implementation. + BOOST_ASIO_DECL void base_move_construct(base_implementation_type& impl, + base_implementation_type& other_impl); + + // Move-assign from another socket implementation. + BOOST_ASIO_DECL void base_move_assign(base_implementation_type& impl, + reactive_socket_service_base& other_service, + base_implementation_type& other_impl); + // Destroy a socket implementation. BOOST_ASIO_DECL void destroy(base_implementation_type& impl); @@ -83,7 +93,7 @@ public: base_implementation_type& impl, boost::system::error_code& ec); // Get the native socket representation. - native_type native(base_implementation_type& impl) + native_handle_type native_handle(base_implementation_type& impl) { return impl.socket_; } @@ -124,7 +134,35 @@ public: return ec; } - /// Disable sends or receives on the socket. + // Gets the non-blocking mode of the socket. + bool non_blocking(const base_implementation_type& impl) const + { + return (impl.state_ & socket_ops::user_set_non_blocking) != 0; + } + + // Sets the non-blocking mode of the socket. + boost::system::error_code non_blocking(base_implementation_type& impl, + bool mode, boost::system::error_code& ec) + { + socket_ops::set_user_non_blocking(impl.socket_, impl.state_, mode, ec); + return ec; + } + + // Gets the non-blocking mode of the native socket implementation. + bool native_non_blocking(const base_implementation_type& impl) const + { + return (impl.state_ & socket_ops::internal_non_blocking) != 0; + } + + // Sets the non-blocking mode of the native socket implementation. + boost::system::error_code native_non_blocking(base_implementation_type& impl, + bool mode, boost::system::error_code& ec) + { + socket_ops::set_internal_non_blocking(impl.socket_, impl.state_, mode, ec); + return ec; + } + + // Disable sends or receives on the socket. boost::system::error_code shutdown(base_implementation_type& impl, socket_base::shutdown_type what, boost::system::error_code& ec) { @@ -150,7 +188,7 @@ public: socket_base::message_flags, boost::system::error_code& ec) { // Wait for socket to become ready. - socket_ops::poll_write(impl.socket_, ec); + socket_ops::poll_write(impl.socket_, impl.state_, ec); return 0; } @@ -169,6 +207,8 @@ public: sizeof(op), handler), 0 }; p.p = new (p.v) op(impl.socket_, buffers, flags, handler); + BOOST_ASIO_HANDLER_CREATION((p.p, "socket", &impl, "async_send")); + start_op(impl, reactor::write_op, p.p, true, ((impl.state_ & socket_ops::stream_oriented) && buffer_sequence_adapter<boost::asio::const_buffer, @@ -188,6 +228,9 @@ public: sizeof(op), handler), 0 }; p.p = new (p.v) op(handler); + BOOST_ASIO_HANDLER_CREATION((p.p, "socket", + &impl, "async_send(null_buffers)")); + start_op(impl, reactor::write_op, p.p, false, false); p.v = p.p = 0; } @@ -210,7 +253,7 @@ public: socket_base::message_flags, boost::system::error_code& ec) { // Wait for socket to become ready. - socket_ops::poll_read(impl.socket_, ec); + socket_ops::poll_read(impl.socket_, impl.state_, ec); return 0; } @@ -229,6 +272,8 @@ public: sizeof(op), handler), 0 }; p.p = new (p.v) op(impl.socket_, impl.state_, buffers, flags, handler); + BOOST_ASIO_HANDLER_CREATION((p.p, "socket", &impl, "async_receive")); + start_op(impl, (flags & socket_base::message_out_of_band) ? reactor::except_op : reactor::read_op, @@ -251,6 +296,9 @@ public: sizeof(op), handler), 0 }; p.p = new (p.v) op(handler); + BOOST_ASIO_HANDLER_CREATION((p.p, "socket", + &impl, "async_receive(null_buffers)")); + start_op(impl, (flags & socket_base::message_out_of_band) ? reactor::except_op : reactor::read_op, @@ -258,6 +306,87 @@ public: p.v = p.p = 0; } + // Receive some data with associated flags. Returns the number of bytes + // received. + template <typename MutableBufferSequence> + size_t receive_with_flags(base_implementation_type& impl, + const MutableBufferSequence& buffers, + socket_base::message_flags in_flags, + socket_base::message_flags& out_flags, boost::system::error_code& ec) + { + buffer_sequence_adapter<boost::asio::mutable_buffer, + MutableBufferSequence> bufs(buffers); + + return socket_ops::sync_recvmsg(impl.socket_, impl.state_, + bufs.buffers(), bufs.count(), in_flags, out_flags, ec); + } + + // Wait until data can be received without blocking. + size_t receive_with_flags(base_implementation_type& impl, + const null_buffers&, socket_base::message_flags, + socket_base::message_flags& out_flags, boost::system::error_code& ec) + { + // Wait for socket to become ready. + socket_ops::poll_read(impl.socket_, impl.state_, ec); + + // Clear out_flags, since we cannot give it any other sensible value when + // performing a null_buffers operation. + out_flags = 0; + + return 0; + } + + // Start an asynchronous receive. The buffer for the data being received + // must be valid for the lifetime of the asynchronous operation. + template <typename MutableBufferSequence, typename Handler> + void async_receive_with_flags(base_implementation_type& impl, + const MutableBufferSequence& buffers, socket_base::message_flags in_flags, + socket_base::message_flags& out_flags, Handler handler) + { + // Allocate and construct an operation to wrap the handler. + typedef reactive_socket_recvmsg_op<MutableBufferSequence, Handler> op; + typename op::ptr p = { boost::addressof(handler), + boost_asio_handler_alloc_helpers::allocate( + sizeof(op), handler), 0 }; + p.p = new (p.v) op(impl.socket_, buffers, in_flags, out_flags, handler); + + BOOST_ASIO_HANDLER_CREATION((p.p, "socket", + &impl, "async_receive_with_flags")); + + start_op(impl, + (in_flags & socket_base::message_out_of_band) + ? reactor::except_op : reactor::read_op, + p.p, (in_flags & socket_base::message_out_of_band) == 0, false); + p.v = p.p = 0; + } + + // Wait until data can be received without blocking. + template <typename Handler> + void async_receive_with_flags(base_implementation_type& impl, + const null_buffers&, socket_base::message_flags in_flags, + socket_base::message_flags& out_flags, Handler handler) + { + // Allocate and construct an operation to wrap the handler. + typedef reactive_null_buffers_op<Handler> op; + typename op::ptr p = { boost::addressof(handler), + boost_asio_handler_alloc_helpers::allocate( + sizeof(op), handler), 0 }; + p.p = new (p.v) op(handler); + + BOOST_ASIO_HANDLER_CREATION((p.p, "socket", &impl, + "async_receive_with_flags(null_buffers)")); + + // Clear out_flags, since we cannot give it any other sensible value when + // performing a null_buffers operation. + out_flags = 0; + + start_op(impl, + (in_flags & socket_base::message_out_of_band) + ? reactor::except_op : reactor::read_op, + p.p, false, false); + p.v = p.p = 0; + } + protected: // Open a new socket implementation. BOOST_ASIO_DECL boost::system::error_code do_open( @@ -267,11 +396,11 @@ protected: // Assign a native socket to a socket implementation. BOOST_ASIO_DECL boost::system::error_code do_assign( base_implementation_type& impl, int type, - const native_type& native_socket, boost::system::error_code& ec); + const native_handle_type& native_socket, boost::system::error_code& ec); // Start the asynchronous read or write operation. BOOST_ASIO_DECL void start_op(base_implementation_type& impl, int op_type, - reactor_op* op, bool non_blocking, bool noop); + reactor_op* op, bool is_non_blocking, bool noop); // Start the asynchronous accept operation. BOOST_ASIO_DECL void start_accept_op(base_implementation_type& impl, |