diff options
Diffstat (limited to '3rdParty/Boost/src/boost/asio/impl/read_at.hpp')
-rw-r--r-- | 3rdParty/Boost/src/boost/asio/impl/read_at.hpp | 199 |
1 files changed, 133 insertions, 66 deletions
diff --git a/3rdParty/Boost/src/boost/asio/impl/read_at.hpp b/3rdParty/Boost/src/boost/asio/impl/read_at.hpp index 08e37fe..877a7c7 100644 --- a/3rdParty/Boost/src/boost/asio/impl/read_at.hpp +++ b/3rdParty/Boost/src/boost/asio/impl/read_at.hpp @@ -2,7 +2,7 @@ // impl/read_at.hpp // ~~~~~~~~~~~~~~~~ // -// Copyright (c) 2003-2012 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// Copyright (c) 2003-2014 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) @@ -24,6 +24,7 @@ #include <boost/asio/detail/consuming_buffers.hpp> #include <boost/asio/detail/dependent_type.hpp> #include <boost/asio/detail/handler_alloc_helpers.hpp> +#include <boost/asio/detail/handler_cont_helpers.hpp> #include <boost/asio/detail/handler_invoke_helpers.hpp> #include <boost/asio/detail/handler_type_requirements.hpp> #include <boost/asio/detail/throw_error.hpp> @@ -37,7 +38,7 @@ namespace asio { template <typename SyncRandomAccessReadDevice, typename MutableBufferSequence, typename CompletionCondition> std::size_t read_at(SyncRandomAccessReadDevice& d, - boost::uint64_t offset, const MutableBufferSequence& buffers, + uint64_t offset, const MutableBufferSequence& buffers, CompletionCondition completion_condition, boost::system::error_code& ec) { ec = boost::system::error_code(); @@ -60,7 +61,7 @@ std::size_t read_at(SyncRandomAccessReadDevice& d, template <typename SyncRandomAccessReadDevice, typename MutableBufferSequence> inline std::size_t read_at(SyncRandomAccessReadDevice& d, - boost::uint64_t offset, const MutableBufferSequence& buffers) + uint64_t offset, const MutableBufferSequence& buffers) { boost::system::error_code ec; std::size_t bytes_transferred = read_at( @@ -71,7 +72,7 @@ inline std::size_t read_at(SyncRandomAccessReadDevice& d, template <typename SyncRandomAccessReadDevice, typename MutableBufferSequence> inline std::size_t read_at(SyncRandomAccessReadDevice& d, - boost::uint64_t offset, const MutableBufferSequence& buffers, + uint64_t offset, const MutableBufferSequence& buffers, boost::system::error_code& ec) { return read_at(d, offset, buffers, transfer_all(), ec); @@ -80,7 +81,7 @@ inline std::size_t read_at(SyncRandomAccessReadDevice& d, template <typename SyncRandomAccessReadDevice, typename MutableBufferSequence, typename CompletionCondition> inline std::size_t read_at(SyncRandomAccessReadDevice& d, - boost::uint64_t offset, const MutableBufferSequence& buffers, + uint64_t offset, const MutableBufferSequence& buffers, CompletionCondition completion_condition) { boost::system::error_code ec; @@ -90,12 +91,12 @@ inline std::size_t read_at(SyncRandomAccessReadDevice& d, return bytes_transferred; } -#if !defined(BOOST_NO_IOSTREAM) +#if !defined(BOOST_ASIO_NO_IOSTREAM) template <typename SyncRandomAccessReadDevice, typename Allocator, typename CompletionCondition> std::size_t read_at(SyncRandomAccessReadDevice& d, - boost::uint64_t offset, boost::asio::basic_streambuf<Allocator>& b, + uint64_t offset, boost::asio::basic_streambuf<Allocator>& b, CompletionCondition completion_condition, boost::system::error_code& ec) { ec = boost::system::error_code(); @@ -118,7 +119,7 @@ std::size_t read_at(SyncRandomAccessReadDevice& d, template <typename SyncRandomAccessReadDevice, typename Allocator> inline std::size_t read_at(SyncRandomAccessReadDevice& d, - boost::uint64_t offset, boost::asio::basic_streambuf<Allocator>& b) + uint64_t offset, boost::asio::basic_streambuf<Allocator>& b) { boost::system::error_code ec; std::size_t bytes_transferred = read_at( @@ -129,7 +130,7 @@ inline std::size_t read_at(SyncRandomAccessReadDevice& d, template <typename SyncRandomAccessReadDevice, typename Allocator> inline std::size_t read_at(SyncRandomAccessReadDevice& d, - boost::uint64_t offset, boost::asio::basic_streambuf<Allocator>& b, + uint64_t offset, boost::asio::basic_streambuf<Allocator>& b, boost::system::error_code& ec) { return read_at(d, offset, b, transfer_all(), ec); @@ -138,7 +139,7 @@ inline std::size_t read_at(SyncRandomAccessReadDevice& d, template <typename SyncRandomAccessReadDevice, typename Allocator, typename CompletionCondition> inline std::size_t read_at(SyncRandomAccessReadDevice& d, - boost::uint64_t offset, boost::asio::basic_streambuf<Allocator>& b, + uint64_t offset, boost::asio::basic_streambuf<Allocator>& b, CompletionCondition completion_condition) { boost::system::error_code ec; @@ -148,7 +149,7 @@ inline std::size_t read_at(SyncRandomAccessReadDevice& d, return bytes_transferred; } -#endif // !defined(BOOST_NO_IOSTREAM) +#endif // !defined(BOOST_ASIO_NO_IOSTREAM) namespace detail { @@ -160,13 +161,14 @@ namespace detail { public: read_at_op(AsyncRandomAccessReadDevice& device, - boost::uint64_t offset, const MutableBufferSequence& buffers, + uint64_t offset, const MutableBufferSequence& buffers, CompletionCondition completion_condition, ReadHandler& handler) : detail::base_from_completion_cond< CompletionCondition>(completion_condition), device_(device), offset_(offset), buffers_(buffers), + start_(0), total_transferred_(0), handler_(BOOST_ASIO_MOVE_CAST(ReadHandler)(handler)) { @@ -178,6 +180,7 @@ namespace detail device_(other.device_), offset_(other.offset_), buffers_(other.buffers_), + start_(other.start_), total_transferred_(other.total_transferred_), handler_(other.handler_) { @@ -188,6 +191,7 @@ namespace detail device_(other.device_), offset_(other.offset_), buffers_(other.buffers_), + start_(other.start_), total_transferred_(other.total_transferred_), handler_(BOOST_ASIO_MOVE_CAST(ReadHandler)(other.handler_)) { @@ -197,7 +201,7 @@ namespace detail void operator()(const boost::system::error_code& ec, std::size_t bytes_transferred, int start = 0) { - switch (start) + switch (start_ = start) { case 1: buffers_.prepare(this->check_for_completion(ec, total_transferred_)); @@ -220,9 +224,10 @@ namespace detail //private: AsyncRandomAccessReadDevice& device_; - boost::uint64_t offset_; + uint64_t offset_; boost::asio::detail::consuming_buffers< mutable_buffer, MutableBufferSequence> buffers_; + int start_; std::size_t total_transferred_; ReadHandler handler_; }; @@ -235,13 +240,14 @@ namespace detail { public: read_at_op(AsyncRandomAccessReadDevice& device, - boost::uint64_t offset, const boost::asio::mutable_buffers_1& buffers, + uint64_t offset, const boost::asio::mutable_buffers_1& buffers, CompletionCondition completion_condition, ReadHandler& handler) : detail::base_from_completion_cond< CompletionCondition>(completion_condition), device_(device), offset_(offset), buffer_(buffers), + start_(0), total_transferred_(0), handler_(BOOST_ASIO_MOVE_CAST(ReadHandler)(handler)) { @@ -253,6 +259,7 @@ namespace detail device_(other.device_), offset_(other.offset_), buffer_(other.buffer_), + start_(other.start_), total_transferred_(other.total_transferred_), handler_(other.handler_) { @@ -263,6 +270,7 @@ namespace detail device_(other.device_), offset_(other.offset_), buffer_(other.buffer_), + start_(other.start_), total_transferred_(other.total_transferred_), handler_(BOOST_ASIO_MOVE_CAST(ReadHandler)(other.handler_)) { @@ -273,7 +281,7 @@ namespace detail std::size_t bytes_transferred, int start = 0) { std::size_t n = 0; - switch (start) + switch (start_ = start) { case 1: n = this->check_for_completion(ec, total_transferred_); @@ -296,8 +304,9 @@ namespace detail //private: AsyncRandomAccessReadDevice& device_; - boost::uint64_t offset_; + uint64_t offset_; boost::asio::mutable_buffer buffer_; + int start_; std::size_t total_transferred_; ReadHandler handler_; }; @@ -310,13 +319,14 @@ namespace detail { public: read_at_op(AsyncRandomAccessReadDevice& device, - boost::uint64_t offset, const boost::array<Elem, 2>& buffers, + uint64_t offset, const boost::array<Elem, 2>& buffers, CompletionCondition completion_condition, ReadHandler& handler) : detail::base_from_completion_cond< CompletionCondition>(completion_condition), device_(device), offset_(offset), buffers_(buffers), + start_(0), total_transferred_(0), handler_(BOOST_ASIO_MOVE_CAST(ReadHandler)(handler)) { @@ -328,6 +338,7 @@ namespace detail device_(other.device_), offset_(other.offset_), buffers_(other.buffers_), + start_(other.start_), total_transferred_(other.total_transferred_), handler_(other.handler_) { @@ -338,6 +349,7 @@ namespace detail device_(other.device_), offset_(other.offset_), buffers_(other.buffers_), + start_(other.start_), total_transferred_(other.total_transferred_), handler_(BOOST_ASIO_MOVE_CAST(ReadHandler)(other.handler_)) { @@ -354,7 +366,7 @@ namespace detail std::size_t buffer_size0 = boost::asio::buffer_size(bufs[0]); std::size_t buffer_size1 = boost::asio::buffer_size(bufs[1]); std::size_t n = 0; - switch (start) + switch (start_ = start) { case 1: n = this->check_for_completion(ec, total_transferred_); @@ -381,8 +393,9 @@ namespace detail //private: AsyncRandomAccessReadDevice& device_; - boost::uint64_t offset_; + uint64_t offset_; boost::array<Elem, 2> buffers_; + int start_; std::size_t total_transferred_; ReadHandler handler_; }; @@ -397,13 +410,14 @@ namespace detail { public: read_at_op(AsyncRandomAccessReadDevice& device, - boost::uint64_t offset, const std::array<Elem, 2>& buffers, + uint64_t offset, const std::array<Elem, 2>& buffers, CompletionCondition completion_condition, ReadHandler& handler) : detail::base_from_completion_cond< CompletionCondition>(completion_condition), device_(device), offset_(offset), buffers_(buffers), + start_(0), total_transferred_(0), handler_(BOOST_ASIO_MOVE_CAST(ReadHandler)(handler)) { @@ -415,6 +429,7 @@ namespace detail device_(other.device_), offset_(other.offset_), buffers_(other.buffers_), + start_(other.start_), total_transferred_(other.total_transferred_), handler_(other.handler_) { @@ -425,6 +440,7 @@ namespace detail device_(other.device_), offset_(other.offset_), buffers_(other.buffers_), + start_(other.start_), total_transferred_(other.total_transferred_), handler_(BOOST_ASIO_MOVE_CAST(ReadHandler)(other.handler_)) { @@ -441,7 +457,7 @@ namespace detail std::size_t buffer_size0 = boost::asio::buffer_size(bufs[0]); std::size_t buffer_size1 = boost::asio::buffer_size(bufs[1]); std::size_t n = 0; - switch (start) + switch (start_ = start) { case 1: n = this->check_for_completion(ec, total_transferred_); @@ -468,8 +484,9 @@ namespace detail //private: AsyncRandomAccessReadDevice& device_; - boost::uint64_t offset_; + uint64_t offset_; std::array<Elem, 2> buffers_; + int start_; std::size_t total_transferred_; ReadHandler handler_; }; @@ -498,6 +515,18 @@ namespace detail pointer, size, this_handler->handler_); } + template <typename AsyncRandomAccessReadDevice, + typename MutableBufferSequence, typename CompletionCondition, + typename ReadHandler> + inline bool asio_handler_is_continuation( + read_at_op<AsyncRandomAccessReadDevice, MutableBufferSequence, + CompletionCondition, ReadHandler>* this_handler) + { + return this_handler->start_ == 0 ? true + : boost_asio_handler_cont_helpers::is_continuation( + this_handler->handler_); + } + template <typename Function, typename AsyncRandomAccessReadDevice, typename MutableBufferSequence, typename CompletionCondition, typename ReadHandler> @@ -526,7 +555,7 @@ namespace detail inline read_at_op<AsyncRandomAccessReadDevice, MutableBufferSequence, CompletionCondition, ReadHandler> make_read_at_op(AsyncRandomAccessReadDevice& d, - boost::uint64_t offset, const MutableBufferSequence& buffers, + uint64_t offset, const MutableBufferSequence& buffers, CompletionCondition completion_condition, ReadHandler handler) { return read_at_op<AsyncRandomAccessReadDevice, @@ -537,8 +566,10 @@ namespace detail template <typename AsyncRandomAccessReadDevice, typename MutableBufferSequence, typename CompletionCondition, typename ReadHandler> -inline void async_read_at(AsyncRandomAccessReadDevice& d, - boost::uint64_t offset, const MutableBufferSequence& buffers, +inline BOOST_ASIO_INITFN_RESULT_TYPE(ReadHandler, + void (boost::system::error_code, std::size_t)) +async_read_at(AsyncRandomAccessReadDevice& d, + uint64_t offset, const MutableBufferSequence& buffers, CompletionCondition completion_condition, BOOST_ASIO_MOVE_ARG(ReadHandler) handler) { @@ -546,29 +577,45 @@ inline void async_read_at(AsyncRandomAccessReadDevice& d, // not meet the documented type requirements for a ReadHandler. BOOST_ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check; - detail::make_read_at_op( - d, offset, buffers, completion_condition, - BOOST_ASIO_MOVE_CAST(ReadHandler)(handler))( - boost::system::error_code(), 0, 1); + detail::async_result_init< + ReadHandler, void (boost::system::error_code, std::size_t)> init( + BOOST_ASIO_MOVE_CAST(ReadHandler)(handler)); + + detail::read_at_op<AsyncRandomAccessReadDevice, MutableBufferSequence, + CompletionCondition, BOOST_ASIO_HANDLER_TYPE(ReadHandler, + void (boost::system::error_code, std::size_t))>( + d, offset, buffers, completion_condition, init.handler)( + boost::system::error_code(), 0, 1); + + return init.result.get(); } template <typename AsyncRandomAccessReadDevice, typename MutableBufferSequence, typename ReadHandler> -inline void async_read_at(AsyncRandomAccessReadDevice& d, - boost::uint64_t offset, const MutableBufferSequence& buffers, +inline BOOST_ASIO_INITFN_RESULT_TYPE(ReadHandler, + void (boost::system::error_code, std::size_t)) +async_read_at(AsyncRandomAccessReadDevice& d, + uint64_t offset, const MutableBufferSequence& buffers, BOOST_ASIO_MOVE_ARG(ReadHandler) handler) { // If you get an error on the following line it means that your handler does // not meet the documented type requirements for a ReadHandler. BOOST_ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check; - detail::make_read_at_op( - d, offset, buffers, transfer_all(), - BOOST_ASIO_MOVE_CAST(ReadHandler)(handler))( - boost::system::error_code(), 0, 1); + detail::async_result_init< + ReadHandler, void (boost::system::error_code, std::size_t)> init( + BOOST_ASIO_MOVE_CAST(ReadHandler)(handler)); + + detail::read_at_op<AsyncRandomAccessReadDevice, MutableBufferSequence, + detail::transfer_all_t, BOOST_ASIO_HANDLER_TYPE(ReadHandler, + void (boost::system::error_code, std::size_t))>( + d, offset, buffers, transfer_all(), init.handler)( + boost::system::error_code(), 0, 1); + + return init.result.get(); } -#if !defined(BOOST_NO_IOSTREAM) +#if !defined(BOOST_ASIO_NO_IOSTREAM) namespace detail { @@ -579,13 +626,14 @@ namespace detail { public: read_at_streambuf_op(AsyncRandomAccessReadDevice& device, - boost::uint64_t offset, basic_streambuf<Allocator>& streambuf, + uint64_t offset, basic_streambuf<Allocator>& streambuf, CompletionCondition completion_condition, ReadHandler& handler) : detail::base_from_completion_cond< CompletionCondition>(completion_condition), device_(device), offset_(offset), streambuf_(streambuf), + start_(0), total_transferred_(0), handler_(BOOST_ASIO_MOVE_CAST(ReadHandler)(handler)) { @@ -597,6 +645,7 @@ namespace detail device_(other.device_), offset_(other.offset_), streambuf_(other.streambuf_), + start_(other.start_), total_transferred_(other.total_transferred_), handler_(other.handler_) { @@ -607,6 +656,7 @@ namespace detail device_(other.device_), offset_(other.offset_), streambuf_(other.streambuf_), + start_(other.start_), total_transferred_(other.total_transferred_), handler_(BOOST_ASIO_MOVE_CAST(ReadHandler)(other.handler_)) { @@ -617,7 +667,7 @@ namespace detail std::size_t bytes_transferred, int start = 0) { std::size_t max_size, bytes_available; - switch (start) + switch (start_ = start) { case 1: max_size = this->check_for_completion(ec, total_transferred_); @@ -642,8 +692,9 @@ namespace detail //private: AsyncRandomAccessReadDevice& device_; - boost::uint64_t offset_; + uint64_t offset_; boost::asio::basic_streambuf<Allocator>& streambuf_; + int start_; std::size_t total_transferred_; ReadHandler handler_; }; @@ -668,6 +719,17 @@ namespace detail pointer, size, this_handler->handler_); } + template <typename AsyncRandomAccessReadDevice, typename Allocator, + typename CompletionCondition, typename ReadHandler> + inline bool asio_handler_is_continuation( + read_at_streambuf_op<AsyncRandomAccessReadDevice, Allocator, + CompletionCondition, ReadHandler>* this_handler) + { + return this_handler->start_ == 0 ? true + : boost_asio_handler_cont_helpers::is_continuation( + this_handler->handler_); + } + template <typename Function, typename AsyncRandomAccessReadDevice, typename Allocator, typename CompletionCondition, typename ReadHandler> inline void asio_handler_invoke(Function& function, @@ -687,25 +749,14 @@ namespace detail boost_asio_handler_invoke_helpers::invoke( function, this_handler->handler_); } - - template <typename AsyncRandomAccessReadDevice, typename Allocator, - typename CompletionCondition, typename ReadHandler> - inline read_at_streambuf_op<AsyncRandomAccessReadDevice, - Allocator, CompletionCondition, ReadHandler> - make_read_at_streambuf_op(AsyncRandomAccessReadDevice& d, - boost::uint64_t offset, boost::asio::basic_streambuf<Allocator>& b, - CompletionCondition completion_condition, ReadHandler handler) - { - return read_at_streambuf_op<AsyncRandomAccessReadDevice, - Allocator, CompletionCondition, ReadHandler>( - d, offset, b, completion_condition, handler); - } } // namespace detail template <typename AsyncRandomAccessReadDevice, typename Allocator, typename CompletionCondition, typename ReadHandler> -inline void async_read_at(AsyncRandomAccessReadDevice& d, - boost::uint64_t offset, boost::asio::basic_streambuf<Allocator>& b, +inline BOOST_ASIO_INITFN_RESULT_TYPE(ReadHandler, + void (boost::system::error_code, std::size_t)) +async_read_at(AsyncRandomAccessReadDevice& d, + uint64_t offset, boost::asio::basic_streambuf<Allocator>& b, CompletionCondition completion_condition, BOOST_ASIO_MOVE_ARG(ReadHandler) handler) { @@ -713,29 +764,45 @@ inline void async_read_at(AsyncRandomAccessReadDevice& d, // not meet the documented type requirements for a ReadHandler. BOOST_ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check; - detail::make_read_at_streambuf_op( - d, offset, b, completion_condition, - BOOST_ASIO_MOVE_CAST(ReadHandler)(handler))( - boost::system::error_code(), 0, 1); + detail::async_result_init< + ReadHandler, void (boost::system::error_code, std::size_t)> init( + BOOST_ASIO_MOVE_CAST(ReadHandler)(handler)); + + detail::read_at_streambuf_op<AsyncRandomAccessReadDevice, Allocator, + CompletionCondition, BOOST_ASIO_HANDLER_TYPE(ReadHandler, + void (boost::system::error_code, std::size_t))>( + d, offset, b, completion_condition, init.handler)( + boost::system::error_code(), 0, 1); + + return init.result.get(); } template <typename AsyncRandomAccessReadDevice, typename Allocator, typename ReadHandler> -inline void async_read_at(AsyncRandomAccessReadDevice& d, - boost::uint64_t offset, boost::asio::basic_streambuf<Allocator>& b, +inline BOOST_ASIO_INITFN_RESULT_TYPE(ReadHandler, + void (boost::system::error_code, std::size_t)) +async_read_at(AsyncRandomAccessReadDevice& d, + uint64_t offset, boost::asio::basic_streambuf<Allocator>& b, BOOST_ASIO_MOVE_ARG(ReadHandler) handler) { // If you get an error on the following line it means that your handler does // not meet the documented type requirements for a ReadHandler. BOOST_ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check; - detail::make_read_at_streambuf_op( - d, offset, b, transfer_all(), - BOOST_ASIO_MOVE_CAST(ReadHandler)(handler))( - boost::system::error_code(), 0, 1); + detail::async_result_init< + ReadHandler, void (boost::system::error_code, std::size_t)> init( + BOOST_ASIO_MOVE_CAST(ReadHandler)(handler)); + + detail::read_at_streambuf_op<AsyncRandomAccessReadDevice, Allocator, + detail::transfer_all_t, BOOST_ASIO_HANDLER_TYPE(ReadHandler, + void (boost::system::error_code, std::size_t))>( + d, offset, b, transfer_all(), init.handler)( + boost::system::error_code(), 0, 1); + + return init.result.get(); } -#endif // !defined(BOOST_NO_IOSTREAM) +#endif // !defined(BOOST_ASIO_NO_IOSTREAM) } // namespace asio } // namespace boost |