diff options
Diffstat (limited to '3rdParty/Boost/src/boost/asio/detail/win_iocp_socket_service.hpp')
-rw-r--r-- | 3rdParty/Boost/src/boost/asio/detail/win_iocp_socket_service.hpp | 132 |
1 files changed, 58 insertions, 74 deletions
diff --git a/3rdParty/Boost/src/boost/asio/detail/win_iocp_socket_service.hpp b/3rdParty/Boost/src/boost/asio/detail/win_iocp_socket_service.hpp index 5192612..e0c0806 100644 --- a/3rdParty/Boost/src/boost/asio/detail/win_iocp_socket_service.hpp +++ b/3rdParty/Boost/src/boost/asio/detail/win_iocp_socket_service.hpp @@ -2,7 +2,7 @@ // win_iocp_socket_service.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~ // -// Copyright (c) 2003-2008 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// Copyright (c) 2003-2010 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) @@ -789,7 +789,7 @@ public: // Call the handler. boost_asio_handler_invoke_helpers::invoke( - detail::bind_handler(handler, ec, bytes_transferred), &handler); + detail::bind_handler(handler, ec, bytes_transferred), handler); } static void destroy_impl(operation* op) @@ -823,13 +823,6 @@ public: void async_send(implementation_type& impl, const ConstBufferSequence& buffers, socket_base::message_flags flags, Handler handler) { - if (!is_open(impl)) - { - this->get_io_service().post(bind_handler(handler, - boost::asio::error::bad_descriptor, 0)); - return; - } - #if defined(BOOST_ASIO_ENABLE_CANCELIO) // Update the ID of the thread from which cancellation is safe. if (impl.safe_cancellation_thread_id_ == 0) @@ -845,6 +838,13 @@ public: handler_ptr<alloc_traits> ptr(raw_ptr, iocp_service_, impl.cancel_token_, buffers, handler); + if (!is_open(impl)) + { + ptr.get()->on_immediate_completion(WSAEBADF, 0); + ptr.release(); + return; + } + // Copy buffers into WSABUF array. ::WSABUF bufs[max_buffers]; typename ConstBufferSequence::const_iterator iter = buffers.begin(); @@ -863,10 +863,8 @@ public: // A request to receive 0 bytes on a stream socket is a no-op. if (impl.protocol_.type() == SOCK_STREAM && total_buffer_size == 0) { - boost::asio::io_service::work work(this->get_io_service()); - ptr.reset(); - boost::system::error_code error; - iocp_service_.post(bind_handler(handler, error, 0)); + ptr.get()->on_immediate_completion(0, 0); + ptr.release(); return; } @@ -879,14 +877,12 @@ public: // Check if the operation completed immediately. if (result != 0 && last_error != WSA_IO_PENDING) { - boost::asio::io_service::work work(this->get_io_service()); - ptr.reset(); - boost::system::error_code ec(last_error, - boost::asio::error::get_system_category()); - iocp_service_.post(bind_handler(handler, ec, bytes_transferred)); + ptr.get()->on_immediate_completion(last_error, bytes_transferred); + ptr.release(); } else { + ptr.get()->on_pending(); ptr.release(); } } @@ -1068,7 +1064,7 @@ public: // Call the handler. boost_asio_handler_invoke_helpers::invoke( - detail::bind_handler(handler, ec, bytes_transferred), &handler); + detail::bind_handler(handler, ec, bytes_transferred), handler); } static void destroy_impl(operation* op) @@ -1102,13 +1098,6 @@ public: const ConstBufferSequence& buffers, const endpoint_type& destination, socket_base::message_flags flags, Handler handler) { - if (!is_open(impl)) - { - this->get_io_service().post(bind_handler(handler, - boost::asio::error::bad_descriptor, 0)); - return; - } - #if defined(BOOST_ASIO_ENABLE_CANCELIO) // Update the ID of the thread from which cancellation is safe. if (impl.safe_cancellation_thread_id_ == 0) @@ -1123,6 +1112,13 @@ public: raw_handler_ptr<alloc_traits> raw_ptr(handler); handler_ptr<alloc_traits> ptr(raw_ptr, iocp_service_, buffers, handler); + if (!is_open(impl)) + { + ptr.get()->on_immediate_completion(WSAEBADF, 0); + ptr.release(); + return; + } + // Copy buffers into WSABUF array. ::WSABUF bufs[max_buffers]; typename ConstBufferSequence::const_iterator iter = buffers.begin(); @@ -1145,14 +1141,12 @@ public: // Check if the operation completed immediately. if (result != 0 && last_error != WSA_IO_PENDING) { - boost::asio::io_service::work work(this->get_io_service()); - ptr.reset(); - boost::system::error_code ec(last_error, - boost::asio::error::get_system_category()); - iocp_service_.post(bind_handler(handler, ec, bytes_transferred)); + ptr.get()->on_immediate_completion(last_error, bytes_transferred); + ptr.release(); } else { + ptr.get()->on_pending(); ptr.release(); } } @@ -1339,7 +1333,7 @@ public: // Call the handler. boost_asio_handler_invoke_helpers::invoke( - detail::bind_handler(handler, ec, bytes_transferred), &handler); + detail::bind_handler(handler, ec, bytes_transferred), handler); } static void destroy_impl(operation* op) @@ -1375,13 +1369,6 @@ public: const MutableBufferSequence& buffers, socket_base::message_flags flags, Handler handler) { - if (!is_open(impl)) - { - this->get_io_service().post(bind_handler(handler, - boost::asio::error::bad_descriptor, 0)); - return; - } - #if defined(BOOST_ASIO_ENABLE_CANCELIO) // Update the ID of the thread from which cancellation is safe. if (impl.safe_cancellation_thread_id_ == 0) @@ -1398,6 +1385,13 @@ public: handler_ptr<alloc_traits> ptr(raw_ptr, protocol_type, iocp_service_, impl.cancel_token_, buffers, handler); + if (!is_open(impl)) + { + ptr.get()->on_immediate_completion(WSAEBADF, 0); + ptr.release(); + return; + } + // Copy buffers into WSABUF array. ::WSABUF bufs[max_buffers]; typename MutableBufferSequence::const_iterator iter = buffers.begin(); @@ -1415,10 +1409,8 @@ public: // A request to receive 0 bytes on a stream socket is a no-op. if (impl.protocol_.type() == SOCK_STREAM && total_buffer_size == 0) { - boost::asio::io_service::work work(this->get_io_service()); - ptr.reset(); - boost::system::error_code error; - iocp_service_.post(bind_handler(handler, error, 0)); + ptr.get()->on_immediate_completion(0, 0); + ptr.release(); return; } @@ -1430,14 +1422,12 @@ public: DWORD last_error = ::WSAGetLastError(); if (result != 0 && last_error != WSA_IO_PENDING) { - boost::asio::io_service::work work(this->get_io_service()); - ptr.reset(); - boost::system::error_code ec(last_error, - boost::asio::error::get_system_category()); - iocp_service_.post(bind_handler(handler, ec, bytes_transferred)); + ptr.get()->on_immediate_completion(last_error, bytes_transferred); + ptr.release(); } else { + ptr.get()->on_pending(); ptr.release(); } } @@ -1482,14 +1472,12 @@ public: DWORD last_error = ::WSAGetLastError(); if (result != 0 && last_error != WSA_IO_PENDING) { - boost::asio::io_service::work work(this->get_io_service()); - ptr.reset(); - boost::system::error_code ec(last_error, - boost::asio::error::get_system_category()); - iocp_service_.post(bind_handler(handler, ec, bytes_transferred)); + ptr.get()->on_immediate_completion(last_error, bytes_transferred); + ptr.release(); } else { + ptr.get()->on_pending(); ptr.release(); } } @@ -1672,7 +1660,7 @@ public: // Call the handler. boost_asio_handler_invoke_helpers::invoke( - detail::bind_handler(handler, ec, bytes_transferred), &handler); + detail::bind_handler(handler, ec, bytes_transferred), handler); } static void destroy_impl(operation* op) @@ -1710,13 +1698,6 @@ public: const MutableBufferSequence& buffers, endpoint_type& sender_endp, socket_base::message_flags flags, Handler handler) { - if (!is_open(impl)) - { - this->get_io_service().post(bind_handler(handler, - boost::asio::error::bad_descriptor, 0)); - return; - } - #if defined(BOOST_ASIO_ENABLE_CANCELIO) // Update the ID of the thread from which cancellation is safe. if (impl.safe_cancellation_thread_id_ == 0) @@ -1733,6 +1714,13 @@ public: handler_ptr<alloc_traits> ptr(raw_ptr, protocol_type, iocp_service_, sender_endp, buffers, handler); + if (!is_open(impl)) + { + ptr.get()->on_immediate_completion(WSAEBADF, 0); + ptr.release(); + return; + } + // Copy buffers into WSABUF array. ::WSABUF bufs[max_buffers]; typename MutableBufferSequence::const_iterator iter = buffers.begin(); @@ -1754,14 +1742,12 @@ public: DWORD last_error = ::WSAGetLastError(); if (result != 0 && last_error != WSA_IO_PENDING) { - boost::asio::io_service::work work(this->get_io_service()); - ptr.reset(); - boost::system::error_code ec(last_error, - boost::asio::error::get_system_category()); - iocp_service_.post(bind_handler(handler, ec, bytes_transferred)); + ptr.get()->on_immediate_completion(last_error, bytes_transferred); + ptr.release(); } else { + ptr.get()->on_pending(); ptr.release(); } } @@ -1925,11 +1911,7 @@ public: && !ptr.get()->enable_connection_aborted_) { // Reset OVERLAPPED structure. - ptr.get()->Internal = 0; - ptr.get()->InternalHigh = 0; - ptr.get()->Offset = 0; - ptr.get()->OffsetHigh = 0; - ptr.get()->hEvent = 0; + ptr.get()->reset(); // Create a new socket for the next connection, since the AcceptEx call // fails with WSAEINVAL if we try to reuse the same socket. @@ -1954,7 +1936,7 @@ public: || last_error == WSAECONNABORTED) { // Post this handler so that operation will be restarted again. - ptr.get()->io_service_.post_completion(ptr.get(), last_error, 0); + ptr.get()->on_immediate_completion(last_error, 0); ptr.release(); return; } @@ -1966,6 +1948,7 @@ public: else { // Asynchronous operation has been successfully restarted. + ptr.get()->on_pending(); ptr.release(); return; } @@ -2038,7 +2021,7 @@ public: boost::system::error_code ec(last_error, boost::asio::error::get_system_category()); boost_asio_handler_invoke_helpers::invoke( - detail::bind_handler(handler, ec), &handler); + detail::bind_handler(handler, ec), handler); } static void destroy_impl(operation* op) @@ -2141,7 +2124,7 @@ public: // Post handler so that operation will be restarted again. We do not // perform the AcceptEx again here to avoid the possibility of starving // other handlers. - iocp_service_.post_completion(ptr.get(), last_error, 0); + ptr.get()->on_immediate_completion(last_error, 0); ptr.release(); } else @@ -2155,6 +2138,7 @@ public: } else { + ptr.get()->on_pending(); ptr.release(); } } |