diff options
Diffstat (limited to '3rdParty/Boost/src/boost/asio/impl/read_until.hpp')
-rw-r--r-- | 3rdParty/Boost/src/boost/asio/impl/read_until.hpp | 288 |
1 files changed, 235 insertions, 53 deletions
diff --git a/3rdParty/Boost/src/boost/asio/impl/read_until.hpp b/3rdParty/Boost/src/boost/asio/impl/read_until.hpp index 5eeb1bc..1b9a8f3 100644 --- a/3rdParty/Boost/src/boost/asio/impl/read_until.hpp +++ b/3rdParty/Boost/src/boost/asio/impl/read_until.hpp @@ -2,7 +2,7 @@ // impl/read_until.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) @@ -25,6 +25,7 @@ #include <boost/asio/detail/bind_handler.hpp> #include <boost/asio/detail/handler_alloc_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> #include <boost/asio/detail/push_options.hpp> @@ -38,7 +39,7 @@ inline std::size_t read_until(SyncReadStream& s, { boost::system::error_code ec; std::size_t bytes_transferred = read_until(s, b, delim, ec); - boost::asio::detail::throw_error(ec); + boost::asio::detail::throw_error(ec, "read_until"); return bytes_transferred; } @@ -56,11 +57,11 @@ std::size_t read_until(SyncReadStream& s, typedef boost::asio::buffers_iterator<const_buffers_type> iterator; const_buffers_type buffers = b.data(); iterator begin = iterator::begin(buffers); - iterator start = begin + search_position; + iterator start_pos = begin + search_position; iterator end = iterator::end(buffers); // Look for a match. - iterator iter = std::find(start, end, delim); + iterator iter = std::find(start_pos, end, delim); if (iter != end) { // Found a match. We're done. @@ -94,7 +95,7 @@ inline std::size_t read_until(SyncReadStream& s, { boost::system::error_code ec; std::size_t bytes_transferred = read_until(s, b, delim, ec); - boost::asio::detail::throw_error(ec); + boost::asio::detail::throw_error(ec, "read_until"); return bytes_transferred; } @@ -147,12 +148,12 @@ std::size_t read_until(SyncReadStream& s, typedef boost::asio::buffers_iterator<const_buffers_type> iterator; const_buffers_type buffers = b.data(); iterator begin = iterator::begin(buffers); - iterator start = begin + search_position; + iterator start_pos = begin + search_position; iterator end = iterator::end(buffers); // Look for a match. std::pair<iterator, bool> result = detail::partial_search( - start, end, delim.begin(), delim.end()); + start_pos, end, delim.begin(), delim.end()); if (result.first != end) { if (result.second) @@ -194,7 +195,7 @@ inline std::size_t read_until(SyncReadStream& s, { boost::system::error_code ec; std::size_t bytes_transferred = read_until(s, b, expr, ec); - boost::asio::detail::throw_error(ec); + boost::asio::detail::throw_error(ec, "read_until"); return bytes_transferred; } @@ -212,14 +213,14 @@ std::size_t read_until(SyncReadStream& s, typedef boost::asio::buffers_iterator<const_buffers_type> iterator; const_buffers_type buffers = b.data(); iterator begin = iterator::begin(buffers); - iterator start = begin + search_position; + iterator start_pos = begin + search_position; iterator end = iterator::end(buffers); // Look for a match. boost::match_results<iterator, typename std::vector<boost::sub_match<iterator> >::allocator_type> match_results; - if (regex_search(start, end, match_results, expr, + if (regex_search(start_pos, end, match_results, expr, boost::match_default | boost::match_partial)) { if (match_results[0].matched) @@ -270,11 +271,11 @@ std::size_t read_until(SyncReadStream& s, typedef boost::asio::buffers_iterator<const_buffers_type> iterator; const_buffers_type buffers = b.data(); iterator begin = iterator::begin(buffers); - iterator start = begin + search_position; + iterator start_pos = begin + search_position; iterator end = iterator::end(buffers); // Look for a match. - std::pair<iterator, bool> result = match_condition(start, end); + std::pair<iterator, bool> result = match_condition(start_pos, end); if (result.second) { // Full match. We're done. @@ -314,7 +315,7 @@ inline std::size_t read_until(SyncReadStream& s, { boost::system::error_code ec; std::size_t bytes_transferred = read_until(s, b, match_condition, ec); - boost::asio::detail::throw_error(ec); + boost::asio::detail::throw_error(ec, "read_until"); return bytes_transferred; } @@ -326,15 +327,35 @@ namespace detail public: read_until_delim_op(AsyncReadStream& stream, boost::asio::basic_streambuf<Allocator>& streambuf, - char delim, ReadHandler handler) + char delim, ReadHandler& handler) : stream_(stream), streambuf_(streambuf), delim_(delim), search_position_(0), - handler_(handler) + handler_(BOOST_ASIO_MOVE_CAST(ReadHandler)(handler)) { } +#if defined(BOOST_ASIO_HAS_MOVE) + read_until_delim_op(const read_until_delim_op& other) + : stream_(other.stream_), + streambuf_(other.streambuf_), + delim_(other.delim_), + search_position_(other.search_position_), + handler_(other.handler_) + { + } + + read_until_delim_op(read_until_delim_op&& other) + : stream_(other.stream_), + streambuf_(other.streambuf_), + delim_(other.delim_), + search_position_(other.search_position_), + handler_(BOOST_ASIO_MOVE_CAST(ReadHandler)(other.handler_)) + { + } +#endif // defined(BOOST_ASIO_HAS_MOVE) + void operator()(const boost::system::error_code& ec, std::size_t bytes_transferred, int start = 0) { @@ -352,11 +373,11 @@ namespace detail typedef boost::asio::buffers_iterator<const_buffers_type> iterator; const_buffers_type buffers = streambuf_.data(); iterator begin = iterator::begin(buffers); - iterator start = begin + search_position_; + iterator start_pos = begin + search_position_; iterator end = iterator::end(buffers); // Look for a match. - iterator iter = std::find(start, end, delim_); + iterator iter = std::find(start_pos, end, delim_); if (iter != end) { // Found a match. We're done. @@ -385,7 +406,8 @@ namespace detail break; // Start a new asynchronous read operation to obtain more data. - stream_.async_read_some(streambuf_.prepare(bytes_to_read), *this); + stream_.async_read_some(streambuf_.prepare(bytes_to_read), + BOOST_ASIO_MOVE_CAST(read_until_delim_op)(*this)); return; default: streambuf_.commit(bytes_transferred); if (ec || bytes_transferred == 0) @@ -432,6 +454,16 @@ namespace detail template <typename Function, typename AsyncReadStream, typename Allocator, typename ReadHandler> + inline void asio_handler_invoke(Function& function, + read_until_delim_op<AsyncReadStream, + Allocator, ReadHandler>* this_handler) + { + boost_asio_handler_invoke_helpers::invoke( + function, this_handler->handler_); + } + + template <typename Function, typename AsyncReadStream, typename Allocator, + typename ReadHandler> inline void asio_handler_invoke(const Function& function, read_until_delim_op<AsyncReadStream, Allocator, ReadHandler>* this_handler) @@ -439,16 +471,30 @@ namespace detail boost_asio_handler_invoke_helpers::invoke( function, this_handler->handler_); } + + template <typename AsyncReadStream, typename Allocator, typename ReadHandler> + inline read_until_delim_op<AsyncReadStream, Allocator, ReadHandler> + make_read_until_delim_op(AsyncReadStream& s, + boost::asio::basic_streambuf<Allocator>& b, + char delim, ReadHandler handler) + { + return read_until_delim_op<AsyncReadStream, Allocator, ReadHandler>( + s, b, delim, handler); + } } // namespace detail template <typename AsyncReadStream, typename Allocator, typename ReadHandler> void async_read_until(AsyncReadStream& s, - boost::asio::basic_streambuf<Allocator>& b, char delim, ReadHandler handler) + boost::asio::basic_streambuf<Allocator>& b, char delim, + BOOST_ASIO_MOVE_ARG(ReadHandler) handler) { - detail::read_until_delim_op< - AsyncReadStream, Allocator, ReadHandler>( - s, b, delim, handler)( - boost::system::error_code(), 0, 1); + // 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_until_delim_op( + s, b, delim, BOOST_ASIO_MOVE_CAST(ReadHandler)(handler))( + boost::system::error_code(), 0, 1); } namespace detail @@ -459,15 +505,35 @@ namespace detail public: read_until_delim_string_op(AsyncReadStream& stream, boost::asio::basic_streambuf<Allocator>& streambuf, - const std::string& delim, ReadHandler handler) + const std::string& delim, ReadHandler& handler) : stream_(stream), streambuf_(streambuf), delim_(delim), search_position_(0), - handler_(handler) + handler_(BOOST_ASIO_MOVE_CAST(ReadHandler)(handler)) { } +#if defined(BOOST_ASIO_HAS_MOVE) + read_until_delim_string_op(const read_until_delim_string_op& other) + : stream_(other.stream_), + streambuf_(other.streambuf_), + delim_(other.delim_), + search_position_(other.search_position_), + handler_(other.handler_) + { + } + + read_until_delim_string_op(read_until_delim_string_op&& other) + : stream_(other.stream_), + streambuf_(other.streambuf_), + delim_(BOOST_ASIO_MOVE_CAST(std::string)(other.delim_)), + search_position_(other.search_position_), + handler_(BOOST_ASIO_MOVE_CAST(ReadHandler)(other.handler_)) + { + } +#endif // defined(BOOST_ASIO_HAS_MOVE) + void operator()(const boost::system::error_code& ec, std::size_t bytes_transferred, int start = 0) { @@ -485,12 +551,12 @@ namespace detail typedef boost::asio::buffers_iterator<const_buffers_type> iterator; const_buffers_type buffers = streambuf_.data(); iterator begin = iterator::begin(buffers); - iterator start = begin + search_position_; + iterator start_pos = begin + search_position_; iterator end = iterator::end(buffers); // Look for a match. std::pair<iterator, bool> result = detail::partial_search( - start, end, delim_.begin(), delim_.end()); + start_pos, end, delim_.begin(), delim_.end()); if (result.first != end && result.second) { // Full match. We're done. @@ -529,7 +595,8 @@ namespace detail break; // Start a new asynchronous read operation to obtain more data. - stream_.async_read_some(streambuf_.prepare(bytes_to_read), *this); + stream_.async_read_some(streambuf_.prepare(bytes_to_read), + BOOST_ASIO_MOVE_CAST(read_until_delim_string_op)(*this)); return; default: streambuf_.commit(bytes_transferred); if (ec || bytes_transferred == 0) @@ -576,6 +643,16 @@ namespace detail template <typename Function, typename AsyncReadStream, typename Allocator, typename ReadHandler> + inline void asio_handler_invoke(Function& function, + read_until_delim_string_op<AsyncReadStream, + Allocator, ReadHandler>* this_handler) + { + boost_asio_handler_invoke_helpers::invoke( + function, this_handler->handler_); + } + + template <typename Function, typename AsyncReadStream, + typename Allocator, typename ReadHandler> inline void asio_handler_invoke(const Function& function, read_until_delim_string_op<AsyncReadStream, Allocator, ReadHandler>* this_handler) @@ -583,17 +660,30 @@ namespace detail boost_asio_handler_invoke_helpers::invoke( function, this_handler->handler_); } + + template <typename AsyncReadStream, typename Allocator, typename ReadHandler> + inline read_until_delim_string_op<AsyncReadStream, Allocator, ReadHandler> + make_read_until_delim_string_op(AsyncReadStream& s, + boost::asio::basic_streambuf<Allocator>& b, + const std::string& delim, ReadHandler handler) + { + return read_until_delim_string_op<AsyncReadStream, Allocator, ReadHandler>( + s, b, delim, handler); + } } // namespace detail template <typename AsyncReadStream, typename Allocator, typename ReadHandler> void async_read_until(AsyncReadStream& s, boost::asio::basic_streambuf<Allocator>& b, const std::string& delim, - ReadHandler handler) + BOOST_ASIO_MOVE_ARG(ReadHandler) handler) { - detail::read_until_delim_string_op< - AsyncReadStream, Allocator, ReadHandler>( - s, b, delim, handler)( - boost::system::error_code(), 0, 1); + // 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_until_delim_string_op( + s, b, delim, BOOST_ASIO_MOVE_CAST(ReadHandler)(handler))( + boost::system::error_code(), 0, 1); } namespace detail @@ -605,15 +695,35 @@ namespace detail public: read_until_expr_op(AsyncReadStream& stream, boost::asio::basic_streambuf<Allocator>& streambuf, - const boost::regex& expr, ReadHandler handler) + const boost::regex& expr, ReadHandler& handler) : stream_(stream), streambuf_(streambuf), expr_(expr), search_position_(0), - handler_(handler) + handler_(BOOST_ASIO_MOVE_CAST(ReadHandler)(handler)) { } +#if defined(BOOST_ASIO_HAS_MOVE) + read_until_expr_op(const read_until_expr_op& other) + : stream_(other.stream_), + streambuf_(other.streambuf_), + expr_(other.expr_), + search_position_(other.search_position_), + handler_(other.handler_) + { + } + + read_until_expr_op(read_until_expr_op&& other) + : stream_(other.stream_), + streambuf_(other.streambuf_), + expr_(other.expr_), + search_position_(other.search_position_), + handler_(BOOST_ASIO_MOVE_CAST(ReadHandler)(other.handler_)) + { + } +#endif // defined(BOOST_ASIO_HAS_MOVE) + void operator()(const boost::system::error_code& ec, std::size_t bytes_transferred, int start = 0) { @@ -631,14 +741,14 @@ namespace detail typedef boost::asio::buffers_iterator<const_buffers_type> iterator; const_buffers_type buffers = streambuf_.data(); iterator begin = iterator::begin(buffers); - iterator start = begin + search_position_; + iterator start_pos = begin + search_position_; iterator end = iterator::end(buffers); // Look for a match. boost::match_results<iterator, typename std::vector<boost::sub_match<iterator> >::allocator_type> match_results; - bool match = regex_search(start, end, match_results, expr_, + bool match = regex_search(start_pos, end, match_results, expr_, boost::match_default | boost::match_partial); if (match && match_results[0].matched) { @@ -678,7 +788,8 @@ namespace detail break; // Start a new asynchronous read operation to obtain more data. - stream_.async_read_some(streambuf_.prepare(bytes_to_read), *this); + stream_.async_read_some(streambuf_.prepare(bytes_to_read), + BOOST_ASIO_MOVE_CAST(read_until_expr_op)(*this)); return; default: streambuf_.commit(bytes_transferred); if (ec || bytes_transferred == 0) @@ -727,6 +838,16 @@ namespace detail template <typename Function, typename AsyncReadStream, typename Allocator, typename RegEx, typename ReadHandler> + inline void asio_handler_invoke(Function& function, + read_until_expr_op<AsyncReadStream, + Allocator, RegEx, ReadHandler>* this_handler) + { + boost_asio_handler_invoke_helpers::invoke( + function, this_handler->handler_); + } + + template <typename Function, typename AsyncReadStream, typename Allocator, + typename RegEx, typename ReadHandler> inline void asio_handler_invoke(const Function& function, read_until_expr_op<AsyncReadStream, Allocator, RegEx, ReadHandler>* this_handler) @@ -734,17 +855,31 @@ namespace detail boost_asio_handler_invoke_helpers::invoke( function, this_handler->handler_); } + + template <typename AsyncReadStream, typename Allocator, + typename RegEx, typename ReadHandler> + inline read_until_expr_op<AsyncReadStream, Allocator, RegEx, ReadHandler> + make_read_until_expr_op(AsyncReadStream& s, + boost::asio::basic_streambuf<Allocator>& b, + const RegEx& expr, ReadHandler handler) + { + return read_until_expr_op<AsyncReadStream, Allocator, RegEx, ReadHandler>( + s, b, expr, handler); + } } // namespace detail template <typename AsyncReadStream, typename Allocator, typename ReadHandler> void async_read_until(AsyncReadStream& s, boost::asio::basic_streambuf<Allocator>& b, const boost::regex& expr, - ReadHandler handler) + BOOST_ASIO_MOVE_ARG(ReadHandler) handler) { - detail::read_until_expr_op<AsyncReadStream, - Allocator, boost::regex, ReadHandler>( - s, b, expr, handler)( - boost::system::error_code(), 0, 1); + // 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_until_expr_op( + s, b, expr, BOOST_ASIO_MOVE_CAST(ReadHandler)(handler))( + boost::system::error_code(), 0, 1); } namespace detail @@ -756,15 +891,35 @@ namespace detail public: read_until_match_op(AsyncReadStream& stream, boost::asio::basic_streambuf<Allocator>& streambuf, - MatchCondition match_condition, ReadHandler handler) + MatchCondition match_condition, ReadHandler& handler) : stream_(stream), streambuf_(streambuf), match_condition_(match_condition), search_position_(0), - handler_(handler) + handler_(BOOST_ASIO_MOVE_CAST(ReadHandler)(handler)) { } +#if defined(BOOST_ASIO_HAS_MOVE) + read_until_match_op(const read_until_match_op& other) + : stream_(other.stream_), + streambuf_(other.streambuf_), + match_condition_(other.match_condition_), + search_position_(other.search_position_), + handler_(other.handler_) + { + } + + read_until_match_op(read_until_match_op&& other) + : stream_(other.stream_), + streambuf_(other.streambuf_), + match_condition_(other.match_condition_), + search_position_(other.search_position_), + handler_(BOOST_ASIO_MOVE_CAST(ReadHandler)(other.handler_)) + { + } +#endif // defined(BOOST_ASIO_HAS_MOVE) + void operator()(const boost::system::error_code& ec, std::size_t bytes_transferred, int start = 0) { @@ -782,11 +937,11 @@ namespace detail typedef boost::asio::buffers_iterator<const_buffers_type> iterator; const_buffers_type buffers = streambuf_.data(); iterator begin = iterator::begin(buffers); - iterator start = begin + search_position_; + iterator start_pos = begin + search_position_; iterator end = iterator::end(buffers); // Look for a match. - std::pair<iterator, bool> result = match_condition_(start, end); + std::pair<iterator, bool> result = match_condition_(start_pos, end); if (result.second) { // Full match. We're done. @@ -825,7 +980,8 @@ namespace detail break; // Start a new asynchronous read operation to obtain more data. - stream_.async_read_some(streambuf_.prepare(bytes_to_read), *this); + stream_.async_read_some(streambuf_.prepare(bytes_to_read), + BOOST_ASIO_MOVE_CAST(read_until_match_op)(*this)); return; default: streambuf_.commit(bytes_transferred); if (ec || bytes_transferred == 0) @@ -874,6 +1030,16 @@ namespace detail template <typename Function, typename AsyncReadStream, typename Allocator, typename MatchCondition, typename ReadHandler> + inline void asio_handler_invoke(Function& function, + read_until_match_op<AsyncReadStream, + Allocator, MatchCondition, ReadHandler>* this_handler) + { + boost_asio_handler_invoke_helpers::invoke( + function, this_handler->handler_); + } + + template <typename Function, typename AsyncReadStream, typename Allocator, + typename MatchCondition, typename ReadHandler> inline void asio_handler_invoke(const Function& function, read_until_match_op<AsyncReadStream, Allocator, MatchCondition, ReadHandler>* this_handler) @@ -881,19 +1047,35 @@ namespace detail boost_asio_handler_invoke_helpers::invoke( function, this_handler->handler_); } + + template <typename AsyncReadStream, typename Allocator, + typename MatchCondition, typename ReadHandler> + inline read_until_match_op<AsyncReadStream, Allocator, + MatchCondition, ReadHandler> + make_read_until_match_op(AsyncReadStream& s, + boost::asio::basic_streambuf<Allocator>& b, + MatchCondition match_condition, ReadHandler handler) + { + return read_until_match_op<AsyncReadStream, + Allocator, MatchCondition, ReadHandler>( + s, b, match_condition, handler); + } } // namespace detail template <typename AsyncReadStream, typename Allocator, typename MatchCondition, typename ReadHandler> void async_read_until(AsyncReadStream& s, boost::asio::basic_streambuf<Allocator>& b, - MatchCondition match_condition, ReadHandler handler, + MatchCondition match_condition, BOOST_ASIO_MOVE_ARG(ReadHandler) handler, typename boost::enable_if<is_match_condition<MatchCondition> >::type*) { - detail::read_until_match_op< - AsyncReadStream, Allocator, MatchCondition, ReadHandler>( - s, b, match_condition, handler)( - boost::system::error_code(), 0, 1); + // 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_until_match_op( + s, b, match_condition, BOOST_ASIO_MOVE_CAST(ReadHandler)(handler))( + boost::system::error_code(), 0, 1); } } // namespace asio |