diff options
Diffstat (limited to '3rdParty/Boost/src/boost/asio/detail/impl/reactive_socket_service_base.ipp')
-rw-r--r-- | 3rdParty/Boost/src/boost/asio/detail/impl/reactive_socket_service_base.ipp | 71 |
1 files changed, 61 insertions, 10 deletions
diff --git a/3rdParty/Boost/src/boost/asio/detail/impl/reactive_socket_service_base.ipp b/3rdParty/Boost/src/boost/asio/detail/impl/reactive_socket_service_base.ipp index 31f5bc4..93277e0 100644 --- a/3rdParty/Boost/src/boost/asio/detail/impl/reactive_socket_service_base.ipp +++ b/3rdParty/Boost/src/boost/asio/detail/impl/reactive_socket_service_base.ipp @@ -2,7 +2,7 @@ // detail/reactive_socket_service_base.ipp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // -// 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) @@ -45,12 +45,46 @@ void reactive_socket_service_base::construct( impl.state_ = 0; } +void reactive_socket_service_base::base_move_construct( + reactive_socket_service_base::base_implementation_type& impl, + reactive_socket_service_base::base_implementation_type& other_impl) +{ + impl.socket_ = other_impl.socket_; + other_impl.socket_ = invalid_socket; + + impl.state_ = other_impl.state_; + other_impl.state_ = 0; + + reactor_.move_descriptor(impl.socket_, + impl.reactor_data_, other_impl.reactor_data_); +} + +void reactive_socket_service_base::base_move_assign( + reactive_socket_service_base::base_implementation_type& impl, + reactive_socket_service_base& other_service, + reactive_socket_service_base::base_implementation_type& other_impl) +{ + destroy(impl); + + impl.socket_ = other_impl.socket_; + other_impl.socket_ = invalid_socket; + + impl.state_ = other_impl.state_; + other_impl.state_ = 0; + + other_service.reactor_.move_descriptor(impl.socket_, + impl.reactor_data_, other_impl.reactor_data_); +} + void reactive_socket_service_base::destroy( reactive_socket_service_base::base_implementation_type& impl) { if (impl.socket_ != invalid_socket) { - reactor_.close_descriptor(impl.socket_, impl.reactor_data_); + BOOST_ASIO_HANDLER_OPERATION(("socket", &impl, "close")); + + reactor_.deregister_descriptor(impl.socket_, impl.reactor_data_, + (impl.state_ & socket_ops::possible_dup) == 0); boost::system::error_code ignored_ec; socket_ops::close(impl.socket_, impl.state_, true, ignored_ec); @@ -62,10 +96,24 @@ boost::system::error_code reactive_socket_service_base::close( boost::system::error_code& ec) { if (is_open(impl)) - reactor_.close_descriptor(impl.socket_, impl.reactor_data_); + { + BOOST_ASIO_HANDLER_OPERATION(("socket", &impl, "close")); - if (socket_ops::close(impl.socket_, impl.state_, false, ec) == 0) - construct(impl); + reactor_.deregister_descriptor(impl.socket_, impl.reactor_data_, + (impl.state_ & socket_ops::possible_dup) == 0); + } + + socket_ops::close(impl.socket_, impl.state_, false, ec); + + // The descriptor is closed by the OS even if close() returns an error. + // + // (Actually, POSIX says the state of the descriptor is unspecified. On + // Linux the descriptor is apparently closed anyway; e.g. see + // http://lkml.org/lkml/2005/9/10/129 + // We'll just have to assume that other OSes follow the same behaviour. The + // known exception is when Windows's closesocket() function fails with + // WSAEWOULDBLOCK, but this case is handled inside socket_ops::close(). + construct(impl); return ec; } @@ -80,6 +128,8 @@ boost::system::error_code reactive_socket_service_base::cancel( return ec; } + BOOST_ASIO_HANDLER_OPERATION(("socket", &impl, "cancel")); + reactor_.cancel_ops(impl.socket_, impl.reactor_data_); ec = boost::system::error_code(); return ec; @@ -119,7 +169,7 @@ boost::system::error_code reactive_socket_service_base::do_open( boost::system::error_code reactive_socket_service_base::do_assign( reactive_socket_service_base::base_implementation_type& impl, int type, - const reactive_socket_service_base::native_type& native_socket, + const reactive_socket_service_base::native_handle_type& native_socket, boost::system::error_code& ec) { if (is_open(impl)) @@ -143,22 +193,23 @@ boost::system::error_code reactive_socket_service_base::do_assign( case SOCK_DGRAM: impl.state_ = socket_ops::datagram_oriented; break; default: impl.state_ = 0; break; } + impl.state_ |= socket_ops::possible_dup; ec = boost::system::error_code(); return ec; } void reactive_socket_service_base::start_op( reactive_socket_service_base::base_implementation_type& impl, - int op_type, reactor_op* op, bool non_blocking, bool noop) + int op_type, reactor_op* op, bool is_non_blocking, bool noop) { if (!noop) { if ((impl.state_ & socket_ops::non_blocking) || socket_ops::set_internal_non_blocking( - impl.socket_, impl.state_, op->ec_)) + impl.socket_, impl.state_, true, op->ec_)) { reactor_.start_op(op_type, impl.socket_, - impl.reactor_data_, op, non_blocking); + impl.reactor_data_, op, is_non_blocking); return; } } @@ -185,7 +236,7 @@ void reactive_socket_service_base::start_connect_op( { if ((impl.state_ & socket_ops::non_blocking) || socket_ops::set_internal_non_blocking( - impl.socket_, impl.state_, op->ec_)) + impl.socket_, impl.state_, true, op->ec_)) { if (socket_ops::connect(impl.socket_, addr, addrlen, op->ec_) != 0) { |