summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2010-11-24 20:33:19 (GMT)
committerRemko Tronçon <git@el-tramo.be>2010-11-24 20:35:17 (GMT)
commit332d60c56dfaa11fdd135088279d15cd5983b3d4 (patch)
treedd77717a4e1732da929d5ff8a0471fa3f005e201 /3rdParty/Boost/src/boost/asio/impl
parent90c44a10fec26d2a0935b2d62e82b6a5be028373 (diff)
downloadswift-332d60c56dfaa11fdd135088279d15cd5983b3d4.zip
swift-332d60c56dfaa11fdd135088279d15cd5983b3d4.tar.bz2
Upgraded Boost to 1.45.0.
Diffstat (limited to '3rdParty/Boost/src/boost/asio/impl')
-rw-r--r--3rdParty/Boost/src/boost/asio/impl/error.ipp155
-rw-r--r--3rdParty/Boost/src/boost/asio/impl/io_service.hpp136
-rw-r--r--3rdParty/Boost/src/boost/asio/impl/io_service.ipp141
-rw-r--r--3rdParty/Boost/src/boost/asio/impl/read.hpp (renamed from 3rdParty/Boost/src/boost/asio/impl/read.ipp)85
-rw-r--r--3rdParty/Boost/src/boost/asio/impl/read_at.hpp (renamed from 3rdParty/Boost/src/boost/asio/impl/read_at.ipp)237
-rw-r--r--3rdParty/Boost/src/boost/asio/impl/read_until.hpp904
-rw-r--r--3rdParty/Boost/src/boost/asio/impl/read_until.ipp989
-rw-r--r--3rdParty/Boost/src/boost/asio/impl/serial_port_base.hpp61
-rw-r--r--3rdParty/Boost/src/boost/asio/impl/serial_port_base.ipp106
-rw-r--r--3rdParty/Boost/src/boost/asio/impl/write.hpp (renamed from 3rdParty/Boost/src/boost/asio/impl/write.ipp)66
-rw-r--r--3rdParty/Boost/src/boost/asio/impl/write_at.hpp (renamed from 3rdParty/Boost/src/boost/asio/impl/write_at.ipp)214
11 files changed, 1694 insertions, 1400 deletions
diff --git a/3rdParty/Boost/src/boost/asio/impl/error.ipp b/3rdParty/Boost/src/boost/asio/impl/error.ipp
new file mode 100644
index 0000000..708654e
--- /dev/null
+++ b/3rdParty/Boost/src/boost/asio/impl/error.ipp
@@ -0,0 +1,155 @@
+//
+// impl/error.ipp
+// ~~~~~~~~~~~~~~
+//
+// 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)
+//
+
+#ifndef BOOST_ASIO_IMPL_ERROR_IPP
+#define BOOST_ASIO_IMPL_ERROR_IPP
+
+#if defined(_MSC_VER) && (_MSC_VER >= 1200)
+# pragma once
+#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
+
+#include <boost/asio/detail/config.hpp>
+#include <boost/cerrno.hpp>
+#include <boost/system/error_code.hpp>
+#include <boost/asio/error.hpp>
+
+#include <boost/asio/detail/push_options.hpp>
+
+namespace boost {
+namespace asio {
+namespace error {
+
+#if !defined(BOOST_WINDOWS) && !defined(__CYGWIN__)
+
+namespace detail {
+
+class netdb_category : public boost::system::error_category
+{
+public:
+ const char* name() const
+ {
+ return "asio.netdb";
+ }
+
+ std::string message(int value) const
+ {
+ if (value == error::host_not_found)
+ return "Host not found (authoritative)";
+ if (value == error::host_not_found_try_again)
+ return "Host not found (non-authoritative), try again later";
+ if (value == error::no_data)
+ return "The query is valid, but it does not have associated data";
+ if (value == error::no_recovery)
+ return "A non-recoverable error occurred during database lookup";
+ return "asio.netdb error";
+ }
+};
+
+} // namespace detail
+
+const boost::system::error_category& get_netdb_category()
+{
+ static detail::netdb_category instance;
+ return instance;
+}
+
+namespace detail {
+
+class addrinfo_category : public boost::system::error_category
+{
+public:
+ const char* name() const
+ {
+ return "asio.addrinfo";
+ }
+
+ std::string message(int value) const
+ {
+ if (value == error::service_not_found)
+ return "Service not found";
+ if (value == error::socket_type_not_supported)
+ return "Socket type not supported";
+ return "asio.addrinfo error";
+ }
+};
+
+} // namespace detail
+
+const boost::system::error_category& get_addrinfo_category()
+{
+ static detail::addrinfo_category instance;
+ return instance;
+}
+
+#endif // !defined(BOOST_WINDOWS) && !defined(__CYGWIN__)
+
+namespace detail {
+
+class misc_category : public boost::system::error_category
+{
+public:
+ const char* name() const
+ {
+ return "asio.misc";
+ }
+
+ std::string message(int value) const
+ {
+ if (value == error::already_open)
+ return "Already open";
+ if (value == error::eof)
+ return "End of file";
+ if (value == error::not_found)
+ return "Element not found";
+ if (value == error::fd_set_failure)
+ return "The descriptor does not fit into the select call's fd_set";
+ return "asio.misc error";
+ }
+};
+
+} // namespace detail
+
+const boost::system::error_category& get_misc_category()
+{
+ static detail::misc_category instance;
+ return instance;
+}
+
+namespace detail {
+
+class ssl_category : public boost::system::error_category
+{
+public:
+ const char* name() const
+ {
+ return "asio.ssl";
+ }
+
+ std::string message(int) const
+ {
+ return "asio.ssl error";
+ }
+};
+
+} // namespace detail
+
+const boost::system::error_category& get_ssl_category()
+{
+ static detail::ssl_category instance;
+ return instance;
+}
+
+} // namespace error
+} // namespace asio
+} // namespace boost
+
+#include <boost/asio/detail/pop_options.hpp>
+
+#endif // BOOST_ASIO_IMPL_ERROR_IPP
diff --git a/3rdParty/Boost/src/boost/asio/impl/io_service.hpp b/3rdParty/Boost/src/boost/asio/impl/io_service.hpp
new file mode 100644
index 0000000..3c082cb
--- /dev/null
+++ b/3rdParty/Boost/src/boost/asio/impl/io_service.hpp
@@ -0,0 +1,136 @@
+//
+// impl/io_service.hpp
+// ~~~~~~~~~~~~~~~~~~~
+//
+// 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)
+//
+
+#ifndef BOOST_ASIO_IMPL_IO_SERVICE_HPP
+#define BOOST_ASIO_IMPL_IO_SERVICE_HPP
+
+#if defined(_MSC_VER) && (_MSC_VER >= 1200)
+# pragma once
+#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
+
+#include <boost/asio/detail/service_registry.hpp>
+
+#include <boost/asio/detail/push_options.hpp>
+
+namespace boost {
+namespace asio {
+
+template <typename Service>
+inline Service& use_service(io_service& ios)
+{
+ // Check that Service meets the necessary type requirements.
+ (void)static_cast<io_service::service*>(static_cast<Service*>(0));
+ (void)static_cast<const io_service::id*>(&Service::id);
+
+ return ios.service_registry_->template use_service<Service>();
+}
+
+template <typename Service>
+inline void add_service(io_service& ios, Service* svc)
+{
+ // Check that Service meets the necessary type requirements.
+ (void)static_cast<io_service::service*>(static_cast<Service*>(0));
+ (void)static_cast<const io_service::id*>(&Service::id);
+
+ ios.service_registry_->template add_service<Service>(svc);
+}
+
+template <typename Service>
+inline bool has_service(io_service& ios)
+{
+ // Check that Service meets the necessary type requirements.
+ (void)static_cast<io_service::service*>(static_cast<Service*>(0));
+ (void)static_cast<const io_service::id*>(&Service::id);
+
+ return ios.service_registry_->template has_service<Service>();
+}
+
+} // namespace asio
+} // namespace boost
+
+#include <boost/asio/detail/pop_options.hpp>
+
+#if defined(BOOST_ASIO_HAS_IOCP)
+# include <boost/asio/detail/win_iocp_io_service.hpp>
+#else
+# include <boost/asio/detail/task_io_service.hpp>
+#endif
+
+#include <boost/asio/detail/push_options.hpp>
+
+namespace boost {
+namespace asio {
+
+template <typename Handler>
+inline void io_service::dispatch(Handler handler)
+{
+ impl_.dispatch(handler);
+}
+
+template <typename Handler>
+inline void io_service::post(Handler handler)
+{
+ impl_.post(handler);
+}
+
+template <typename Handler>
+#if defined(GENERATING_DOCUMENTATION)
+unspecified
+#else
+inline detail::wrapped_handler<io_service&, Handler>
+#endif
+io_service::wrap(Handler handler)
+{
+ return detail::wrapped_handler<io_service&, Handler>(*this, handler);
+}
+
+inline io_service::work::work(boost::asio::io_service& io_service)
+ : io_service_(io_service)
+{
+ io_service_.impl_.work_started();
+}
+
+inline io_service::work::work(const work& other)
+ : io_service_(other.io_service_)
+{
+ io_service_.impl_.work_started();
+}
+
+inline io_service::work::~work()
+{
+ io_service_.impl_.work_finished();
+}
+
+inline boost::asio::io_service& io_service::work::io_service()
+{
+ return io_service_;
+}
+
+inline boost::asio::io_service& io_service::work::get_io_service()
+{
+ return io_service_;
+}
+
+inline boost::asio::io_service& io_service::service::io_service()
+{
+ return owner_;
+}
+
+inline boost::asio::io_service& io_service::service::get_io_service()
+{
+ return owner_;
+}
+
+} // namespace asio
+} // namespace boost
+
+#include <boost/asio/detail/pop_options.hpp>
+
+#endif // BOOST_ASIO_IMPL_IO_SERVICE_HPP
diff --git a/3rdParty/Boost/src/boost/asio/impl/io_service.ipp b/3rdParty/Boost/src/boost/asio/impl/io_service.ipp
index 20f868d..731adb8 100644
--- a/3rdParty/Boost/src/boost/asio/impl/io_service.ipp
+++ b/3rdParty/Boost/src/boost/asio/impl/io_service.ipp
@@ -1,6 +1,6 @@
//
-// io_service.ipp
-// ~~~~~~~~~~~~~~
+// impl/io_service.ipp
+// ~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2010 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
@@ -8,19 +8,16 @@
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
-#ifndef BOOST_ASIO_IO_SERVICE_IPP
-#define BOOST_ASIO_IO_SERVICE_IPP
+#ifndef BOOST_ASIO_IMPL_IO_SERVICE_IPP
+#define BOOST_ASIO_IMPL_IO_SERVICE_IPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
-#include <boost/asio/detail/push_options.hpp>
-
-#include <boost/asio/detail/push_options.hpp>
+#include <boost/asio/detail/config.hpp>
#include <boost/limits.hpp>
-#include <boost/asio/detail/pop_options.hpp>
-
+#include <boost/asio/io_service.hpp>
#include <boost/asio/detail/service_registry.hpp>
#include <boost/asio/detail/throw_error.hpp>
@@ -28,32 +25,33 @@
# include <boost/asio/detail/win_iocp_io_service.hpp>
#else
# include <boost/asio/detail/task_io_service.hpp>
-# include <boost/asio/detail/reactor.hpp>
#endif
+#include <boost/asio/detail/push_options.hpp>
+
namespace boost {
namespace asio {
-inline io_service::io_service()
+io_service::io_service()
: service_registry_(new boost::asio::detail::service_registry(*this)),
impl_(service_registry_->use_service<impl_type>())
{
impl_.init((std::numeric_limits<std::size_t>::max)());
}
-inline io_service::io_service(std::size_t concurrency_hint)
+io_service::io_service(std::size_t concurrency_hint)
: service_registry_(new boost::asio::detail::service_registry(*this)),
impl_(service_registry_->use_service<impl_type>())
{
impl_.init(concurrency_hint);
}
-inline io_service::~io_service()
+io_service::~io_service()
{
delete service_registry_;
}
-inline std::size_t io_service::run()
+std::size_t io_service::run()
{
boost::system::error_code ec;
std::size_t s = impl_.run(ec);
@@ -61,12 +59,12 @@ inline std::size_t io_service::run()
return s;
}
-inline std::size_t io_service::run(boost::system::error_code& ec)
+std::size_t io_service::run(boost::system::error_code& ec)
{
return impl_.run(ec);
}
-inline std::size_t io_service::run_one()
+std::size_t io_service::run_one()
{
boost::system::error_code ec;
std::size_t s = impl_.run_one(ec);
@@ -74,12 +72,12 @@ inline std::size_t io_service::run_one()
return s;
}
-inline std::size_t io_service::run_one(boost::system::error_code& ec)
+std::size_t io_service::run_one(boost::system::error_code& ec)
{
return impl_.run_one(ec);
}
-inline std::size_t io_service::poll()
+std::size_t io_service::poll()
{
boost::system::error_code ec;
std::size_t s = impl_.poll(ec);
@@ -87,12 +85,12 @@ inline std::size_t io_service::poll()
return s;
}
-inline std::size_t io_service::poll(boost::system::error_code& ec)
+std::size_t io_service::poll(boost::system::error_code& ec)
{
return impl_.poll(ec);
}
-inline std::size_t io_service::poll_one()
+std::size_t io_service::poll_one()
{
boost::system::error_code ec;
std::size_t s = impl_.poll_one(ec);
@@ -100,122 +98,39 @@ inline std::size_t io_service::poll_one()
return s;
}
-inline std::size_t io_service::poll_one(boost::system::error_code& ec)
+std::size_t io_service::poll_one(boost::system::error_code& ec)
{
return impl_.poll_one(ec);
}
-inline void io_service::stop()
+void io_service::stop()
{
impl_.stop();
}
-inline void io_service::reset()
+void io_service::reset()
{
impl_.reset();
}
-template <typename Handler>
-inline void io_service::dispatch(Handler handler)
-{
- impl_.dispatch(handler);
-}
-
-template <typename Handler>
-inline void io_service::post(Handler handler)
-{
- impl_.post(handler);
-}
-
-template <typename Handler>
-#if defined(GENERATING_DOCUMENTATION)
-unspecified
-#else
-inline detail::wrapped_handler<io_service&, Handler>
-#endif
-io_service::wrap(Handler handler)
-{
- return detail::wrapped_handler<io_service&, Handler>(*this, handler);
-}
-
-inline io_service::work::work(boost::asio::io_service& io_service)
- : io_service_(io_service)
-{
- io_service_.impl_.work_started();
-}
-
-inline io_service::work::work(const work& other)
- : io_service_(other.io_service_)
-{
- io_service_.impl_.work_started();
-}
-
-inline io_service::work::~work()
-{
- io_service_.impl_.work_finished();
-}
-
-inline boost::asio::io_service& io_service::work::io_service()
-{
- return io_service_;
-}
-
-inline boost::asio::io_service& io_service::work::get_io_service()
-{
- return io_service_;
-}
-
-inline io_service::service::service(boost::asio::io_service& owner)
+io_service::service::service(boost::asio::io_service& owner)
: owner_(owner),
next_(0)
{
}
-inline io_service::service::~service()
-{
-}
-
-inline boost::asio::io_service& io_service::service::io_service()
-{
- return owner_;
-}
-
-inline boost::asio::io_service& io_service::service::get_io_service()
+io_service::service::~service()
{
- return owner_;
}
-template <typename Service>
-inline Service& use_service(io_service& ios)
+service_already_exists::service_already_exists()
+ : std::logic_error("Service already exists.")
{
- // Check that Service meets the necessary type requirements.
- (void)static_cast<io_service::service*>(static_cast<Service*>(0));
- (void)static_cast<const io_service::id*>(&Service::id);
-
- return ios.service_registry_->template use_service<Service>();
}
-template <typename Service>
-void add_service(io_service& ios, Service* svc)
+invalid_service_owner::invalid_service_owner()
+ : std::logic_error("Invalid service owner.")
{
- // Check that Service meets the necessary type requirements.
- (void)static_cast<io_service::service*>(static_cast<Service*>(0));
- (void)static_cast<const io_service::id*>(&Service::id);
-
- if (&ios != &svc->io_service())
- boost::throw_exception(invalid_service_owner());
- if (!ios.service_registry_->template add_service<Service>(svc))
- boost::throw_exception(service_already_exists());
-}
-
-template <typename Service>
-bool has_service(io_service& ios)
-{
- // Check that Service meets the necessary type requirements.
- (void)static_cast<io_service::service*>(static_cast<Service*>(0));
- (void)static_cast<const io_service::id*>(&Service::id);
-
- return ios.service_registry_->template has_service<Service>();
}
} // namespace asio
@@ -223,4 +138,4 @@ bool has_service(io_service& ios)
#include <boost/asio/detail/pop_options.hpp>
-#endif // BOOST_ASIO_IO_SERVICE_IPP
+#endif // BOOST_ASIO_IMPL_IO_SERVICE_IPP
diff --git a/3rdParty/Boost/src/boost/asio/impl/read.ipp b/3rdParty/Boost/src/boost/asio/impl/read.hpp
index 772c06b..6f9842c 100644
--- a/3rdParty/Boost/src/boost/asio/impl/read.ipp
+++ b/3rdParty/Boost/src/boost/asio/impl/read.hpp
@@ -1,6 +1,6 @@
//
-// read.ipp
-// ~~~~~~~~
+// impl/read.hpp
+// ~~~~~~~~~~~~~
//
// Copyright (c) 2003-2010 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
@@ -8,28 +8,25 @@
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
-#ifndef BOOST_ASIO_READ_IPP
-#define BOOST_ASIO_READ_IPP
+#ifndef BOOST_ASIO_IMPL_READ_HPP
+#define BOOST_ASIO_IMPL_READ_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
-#include <boost/asio/detail/push_options.hpp>
-
-#include <boost/asio/detail/push_options.hpp>
#include <algorithm>
-#include <boost/asio/detail/pop_options.hpp>
-
#include <boost/asio/buffer.hpp>
#include <boost/asio/completion_condition.hpp>
-#include <boost/asio/error.hpp>
#include <boost/asio/detail/base_from_completion_cond.hpp>
#include <boost/asio/detail/bind_handler.hpp>
#include <boost/asio/detail/consuming_buffers.hpp>
#include <boost/asio/detail/handler_alloc_helpers.hpp>
#include <boost/asio/detail/handler_invoke_helpers.hpp>
#include <boost/asio/detail/throw_error.hpp>
+#include <boost/asio/error.hpp>
+
+#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
@@ -88,8 +85,7 @@ std::size_t read(SyncReadStream& s,
std::size_t total_transferred = 0;
std::size_t max_size = detail::adapt_completion_condition_result(
completion_condition(ec, total_transferred));
- std::size_t bytes_available = std::min<std::size_t>(512,
- std::min<std::size_t>(max_size, b.max_size() - b.size()));
+ std::size_t bytes_available = read_size_helper(b, max_size);
while (bytes_available > 0)
{
std::size_t bytes_transferred = s.read_some(b.prepare(bytes_available), ec);
@@ -97,8 +93,7 @@ std::size_t read(SyncReadStream& s,
total_transferred += bytes_transferred;
max_size = detail::adapt_completion_condition_result(
completion_condition(ec, total_transferred));
- bytes_available = std::min<std::size_t>(512,
- std::min<std::size_t>(max_size, b.max_size() - b.size()));
+ bytes_available = read_size_helper(b, max_size);
}
return total_transferred;
}
@@ -142,31 +137,30 @@ namespace detail
stream_(stream),
buffers_(buffers),
total_transferred_(0),
- handler_(handler),
- start_(true)
+ handler_(handler)
{
}
void operator()(const boost::system::error_code& ec,
- std::size_t bytes_transferred)
+ std::size_t bytes_transferred, int start = 0)
{
- switch (start_)
+ switch (start)
{
- case true: start_ = false;
- buffers_.prepare(this->check(ec, total_transferred_));
+ case 1:
+ buffers_.prepare(this->check_for_completion(ec, total_transferred_));
for (;;)
{
stream_.async_read_some(buffers_, *this);
return; default:
total_transferred_ += bytes_transferred;
buffers_.consume(bytes_transferred);
- buffers_.prepare(this->check(ec, total_transferred_));
+ buffers_.prepare(this->check_for_completion(ec, total_transferred_));
if ((!ec && bytes_transferred == 0)
|| buffers_.begin() == buffers_.end())
break;
}
- handler_(ec, total_transferred_);
+ handler_(ec, static_cast<const std::size_t&>(total_transferred_));
}
}
@@ -176,7 +170,6 @@ namespace detail
mutable_buffer, MutableBufferSequence> buffers_;
std::size_t total_transferred_;
ReadHandler handler_;
- bool start_;
};
template <typename AsyncReadStream,
@@ -195,19 +188,18 @@ namespace detail
stream_(stream),
buffer_(buffers),
total_transferred_(0),
- handler_(handler),
- start_(true)
+ handler_(handler)
{
}
void operator()(const boost::system::error_code& ec,
- std::size_t bytes_transferred)
+ std::size_t bytes_transferred, int start = 0)
{
std::size_t n = 0;
- switch (start_)
+ switch (start)
{
- case true: start_ = false;
- n = this->check(ec, total_transferred_);
+ case 1:
+ n = this->check_for_completion(ec, total_transferred_);
for (;;)
{
stream_.async_read_some(boost::asio::buffer(
@@ -215,12 +207,12 @@ namespace detail
return; default:
total_transferred_ += bytes_transferred;
if ((!ec && bytes_transferred == 0)
- || (n = this->check(ec, total_transferred_)) == 0
+ || (n = this->check_for_completion(ec, total_transferred_)) == 0
|| total_transferred_ == boost::asio::buffer_size(buffer_))
break;
}
- handler_(ec, total_transferred_);
+ handler_(ec, static_cast<const std::size_t&>(total_transferred_));
}
}
@@ -229,7 +221,6 @@ namespace detail
boost::asio::mutable_buffer buffer_;
std::size_t total_transferred_;
ReadHandler handler_;
- bool start_;
};
template <typename AsyncReadStream, typename MutableBufferSequence,
@@ -272,7 +263,7 @@ inline void async_read(AsyncReadStream& s, const MutableBufferSequence& buffers,
detail::read_op<AsyncReadStream, MutableBufferSequence,
CompletionCondition, ReadHandler>(
s, buffers, completion_condition, handler)(
- boost::system::error_code(), 0);
+ boost::system::error_code(), 0, 1);
}
template <typename AsyncReadStream, typename MutableBufferSequence,
@@ -301,37 +292,32 @@ namespace detail
stream_(stream),
streambuf_(streambuf),
total_transferred_(0),
- handler_(handler),
- start_(true)
+ handler_(handler)
{
}
void operator()(const boost::system::error_code& ec,
- std::size_t bytes_transferred)
+ std::size_t bytes_transferred, int start = 0)
{
std::size_t max_size, bytes_available;
- switch (start_)
+ switch (start)
{
- case true: start_ = false;
- max_size = this->check(ec, total_transferred_);
- bytes_available = std::min<std::size_t>(512,
- std::min<std::size_t>(max_size,
- streambuf_.max_size() - streambuf_.size()));
+ case 1:
+ max_size = this->check_for_completion(ec, total_transferred_);
+ bytes_available = read_size_helper(streambuf_, max_size);
for (;;)
{
stream_.async_read_some(streambuf_.prepare(bytes_available), *this);
return; default:
total_transferred_ += bytes_transferred;
streambuf_.commit(bytes_transferred);
- max_size = this->check(ec, total_transferred_);
- bytes_available = std::min<std::size_t>(512,
- std::min<std::size_t>(max_size,
- streambuf_.max_size() - streambuf_.size()));
+ max_size = this->check_for_completion(ec, total_transferred_);
+ bytes_available = read_size_helper(streambuf_, max_size);
if ((!ec && bytes_transferred == 0) || bytes_available == 0)
break;
}
- handler_(ec, total_transferred_);
+ handler_(ec, static_cast<const std::size_t&>(total_transferred_));
}
}
@@ -340,7 +326,6 @@ namespace detail
boost::asio::basic_streambuf<Allocator>& streambuf_;
std::size_t total_transferred_;
ReadHandler handler_;
- bool start_;
};
template <typename AsyncReadStream, typename Allocator,
@@ -383,7 +368,7 @@ inline void async_read(AsyncReadStream& s,
detail::read_streambuf_op<AsyncReadStream,
Allocator, CompletionCondition, ReadHandler>(
s, b, completion_condition, handler)(
- boost::system::error_code(), 0);
+ boost::system::error_code(), 0, 1);
}
template <typename AsyncReadStream, typename Allocator, typename ReadHandler>
@@ -400,4 +385,4 @@ inline void async_read(AsyncReadStream& s,
#include <boost/asio/detail/pop_options.hpp>
-#endif // BOOST_ASIO_READ_IPP
+#endif // BOOST_ASIO_IMPL_READ_HPP
diff --git a/3rdParty/Boost/src/boost/asio/impl/read_at.ipp b/3rdParty/Boost/src/boost/asio/impl/read_at.hpp
index eb3c3f8..f6ea0b3 100644
--- a/3rdParty/Boost/src/boost/asio/impl/read_at.ipp
+++ b/3rdParty/Boost/src/boost/asio/impl/read_at.hpp
@@ -1,6 +1,6 @@
//
-// read_at.ipp
-// ~~~~~~~~~~~
+// impl/read_at.hpp
+// ~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2010 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
@@ -8,27 +8,25 @@
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
-#ifndef BOOST_ASIO_READ_AT_IPP
-#define BOOST_ASIO_READ_AT_IPP
+#ifndef BOOST_ASIO_IMPL_READ_AT_HPP
+#define BOOST_ASIO_IMPL_READ_AT_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
-#include <boost/asio/detail/push_options.hpp>
-
-#include <boost/asio/detail/push_options.hpp>
#include <algorithm>
-#include <boost/asio/detail/pop_options.hpp>
-
#include <boost/asio/buffer.hpp>
#include <boost/asio/completion_condition.hpp>
-#include <boost/asio/error.hpp>
+#include <boost/asio/detail/base_from_completion_cond.hpp>
#include <boost/asio/detail/bind_handler.hpp>
#include <boost/asio/detail/consuming_buffers.hpp>
#include <boost/asio/detail/handler_alloc_helpers.hpp>
#include <boost/asio/detail/handler_invoke_helpers.hpp>
#include <boost/asio/detail/throw_error.hpp>
+#include <boost/asio/error.hpp>
+
+#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
@@ -89,19 +87,22 @@ std::size_t read_at(SyncRandomAccessReadDevice& d,
boost::uint64_t offset, boost::asio::basic_streambuf<Allocator>& b,
CompletionCondition completion_condition, boost::system::error_code& ec)
{
+ ec = boost::system::error_code();
std::size_t total_transferred = 0;
- for (;;)
+ std::size_t max_size = detail::adapt_completion_condition_result(
+ completion_condition(ec, total_transferred));
+ std::size_t bytes_available = read_size_helper(b, max_size);
+ while (bytes_available > 0)
{
- std::size_t bytes_available =
- std::min<std::size_t>(512, b.max_size() - b.size());
std::size_t bytes_transferred = d.read_some_at(
offset + total_transferred, b.prepare(bytes_available), ec);
b.commit(bytes_transferred);
total_transferred += bytes_transferred;
- if (b.size() == b.max_size()
- || completion_condition(ec, total_transferred))
- return total_transferred;
+ max_size = detail::adapt_completion_condition_result(
+ completion_condition(ec, total_transferred));
+ bytes_available = read_size_helper(b, max_size);
}
+ return total_transferred;
}
template <typename SyncRandomAccessReadDevice, typename Allocator>
@@ -135,48 +136,105 @@ namespace detail
template <typename AsyncRandomAccessReadDevice,
typename MutableBufferSequence, typename CompletionCondition,
typename ReadHandler>
- class read_at_handler
+ class read_at_op
+ : detail::base_from_completion_cond<CompletionCondition>
{
public:
- typedef boost::asio::detail::consuming_buffers<
- mutable_buffer, MutableBufferSequence> buffers_type;
-
- read_at_handler(AsyncRandomAccessReadDevice& stream,
- boost::uint64_t offset, const buffers_type& buffers,
+ read_at_op(AsyncRandomAccessReadDevice& device,
+ boost::uint64_t offset, const MutableBufferSequence& buffers,
CompletionCondition completion_condition, ReadHandler handler)
- : stream_(stream),
+ : detail::base_from_completion_cond<
+ CompletionCondition>(completion_condition),
+ device_(device),
offset_(offset),
buffers_(buffers),
total_transferred_(0),
- completion_condition_(completion_condition),
handler_(handler)
{
}
void operator()(const boost::system::error_code& ec,
- std::size_t bytes_transferred)
+ std::size_t bytes_transferred, int start = 0)
{
- total_transferred_ += bytes_transferred;
- buffers_.consume(bytes_transferred);
- buffers_.prepare(detail::adapt_completion_condition_result(
- completion_condition_(ec, total_transferred_)));
- if (buffers_.begin() == buffers_.end())
+ switch (start)
{
- handler_(ec, total_transferred_);
+ case 1:
+ buffers_.prepare(this->check_for_completion(ec, total_transferred_));
+ for (;;)
+ {
+ device_.async_read_some_at(
+ offset_ + total_transferred_, buffers_, *this);
+ return; default:
+ total_transferred_ += bytes_transferred;
+ buffers_.consume(bytes_transferred);
+ buffers_.prepare(this->check_for_completion(ec, total_transferred_));
+ if ((!ec && bytes_transferred == 0)
+ || buffers_.begin() == buffers_.end())
+ break;
+ }
+
+ handler_(ec, static_cast<const std::size_t&>(total_transferred_));
}
- else
+ }
+
+ //private:
+ AsyncRandomAccessReadDevice& device_;
+ boost::uint64_t offset_;
+ boost::asio::detail::consuming_buffers<
+ mutable_buffer, MutableBufferSequence> buffers_;
+ std::size_t total_transferred_;
+ ReadHandler handler_;
+ };
+
+ template <typename AsyncRandomAccessReadDevice,
+ typename CompletionCondition, typename ReadHandler>
+ class read_at_op<AsyncRandomAccessReadDevice,
+ boost::asio::mutable_buffers_1, CompletionCondition, ReadHandler>
+ : detail::base_from_completion_cond<CompletionCondition>
+ {
+ public:
+ read_at_op(AsyncRandomAccessReadDevice& device,
+ boost::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),
+ total_transferred_(0),
+ handler_(handler)
+ {
+ }
+
+ void operator()(const boost::system::error_code& ec,
+ std::size_t bytes_transferred, int start = 0)
+ {
+ std::size_t n = 0;
+ switch (start)
{
- stream_.async_read_some_at(
- offset_ + total_transferred_, buffers_, *this);
+ case 1:
+ n = this->check_for_completion(ec, total_transferred_);
+ for (;;)
+ {
+ device_.async_read_some_at(offset_ + total_transferred_,
+ boost::asio::buffer(buffer_ + total_transferred_, n), *this);
+ return; default:
+ total_transferred_ += bytes_transferred;
+ if ((!ec && bytes_transferred == 0)
+ || (n = this->check_for_completion(ec, total_transferred_)) == 0
+ || total_transferred_ == boost::asio::buffer_size(buffer_))
+ break;
+ }
+
+ handler_(ec, static_cast<const std::size_t&>(total_transferred_));
}
}
//private:
- AsyncRandomAccessReadDevice& stream_;
+ AsyncRandomAccessReadDevice& device_;
boost::uint64_t offset_;
- buffers_type buffers_;
+ boost::asio::mutable_buffer buffer_;
std::size_t total_transferred_;
- CompletionCondition completion_condition_;
ReadHandler handler_;
};
@@ -184,7 +242,7 @@ namespace detail
typename MutableBufferSequence, typename CompletionCondition,
typename ReadHandler>
inline void* asio_handler_allocate(std::size_t size,
- read_at_handler<AsyncRandomAccessReadDevice, MutableBufferSequence,
+ read_at_op<AsyncRandomAccessReadDevice, MutableBufferSequence,
CompletionCondition, ReadHandler>* this_handler)
{
return boost_asio_handler_alloc_helpers::allocate(
@@ -195,7 +253,7 @@ namespace detail
typename MutableBufferSequence, typename CompletionCondition,
typename ReadHandler>
inline void asio_handler_deallocate(void* pointer, std::size_t size,
- read_at_handler<AsyncRandomAccessReadDevice, MutableBufferSequence,
+ read_at_op<AsyncRandomAccessReadDevice, MutableBufferSequence,
CompletionCondition, ReadHandler>* this_handler)
{
boost_asio_handler_alloc_helpers::deallocate(
@@ -206,7 +264,7 @@ namespace detail
typename MutableBufferSequence, typename CompletionCondition,
typename ReadHandler>
inline void asio_handler_invoke(const Function& function,
- read_at_handler<AsyncRandomAccessReadDevice, MutableBufferSequence,
+ read_at_op<AsyncRandomAccessReadDevice, MutableBufferSequence,
CompletionCondition, ReadHandler>* this_handler)
{
boost_asio_handler_invoke_helpers::invoke(
@@ -220,24 +278,10 @@ inline void async_read_at(AsyncRandomAccessReadDevice& d,
boost::uint64_t offset, const MutableBufferSequence& buffers,
CompletionCondition completion_condition, ReadHandler handler)
{
- boost::asio::detail::consuming_buffers<
- mutable_buffer, MutableBufferSequence> tmp(buffers);
-
- boost::system::error_code ec;
- std::size_t total_transferred = 0;
- tmp.prepare(detail::adapt_completion_condition_result(
- completion_condition(ec, total_transferred)));
- if (tmp.begin() == tmp.end())
- {
- d.get_io_service().post(detail::bind_handler(
- handler, ec, total_transferred));
- return;
- }
-
- d.async_read_some_at(offset, tmp,
- detail::read_at_handler<AsyncRandomAccessReadDevice,
- MutableBufferSequence, CompletionCondition, ReadHandler>(
- d, offset, tmp, completion_condition, handler));
+ detail::read_at_op<AsyncRandomAccessReadDevice,
+ MutableBufferSequence, CompletionCondition, ReadHandler>(
+ d, offset, buffers, completion_condition, handler)(
+ boost::system::error_code(), 0, 1);
}
template <typename AsyncRandomAccessReadDevice, typename MutableBufferSequence,
@@ -255,55 +299,61 @@ namespace detail
{
template <typename AsyncRandomAccessReadDevice, typename Allocator,
typename CompletionCondition, typename ReadHandler>
- class read_at_streambuf_handler
+ class read_at_streambuf_op
+ : detail::base_from_completion_cond<CompletionCondition>
{
public:
- read_at_streambuf_handler(AsyncRandomAccessReadDevice& stream,
+ read_at_streambuf_op(AsyncRandomAccessReadDevice& device,
boost::uint64_t offset, basic_streambuf<Allocator>& streambuf,
CompletionCondition completion_condition, ReadHandler handler)
- : stream_(stream),
+ : detail::base_from_completion_cond<
+ CompletionCondition>(completion_condition),
+ device_(device),
offset_(offset),
streambuf_(streambuf),
total_transferred_(0),
- completion_condition_(completion_condition),
handler_(handler)
{
}
void operator()(const boost::system::error_code& ec,
- std::size_t bytes_transferred)
+ std::size_t bytes_transferred, int start = 0)
{
- total_transferred_ += bytes_transferred;
- streambuf_.commit(bytes_transferred);
- std::size_t max_size = detail::adapt_completion_condition_result(
- completion_condition_(ec, total_transferred_));
- std::size_t bytes_available = std::min<std::size_t>(512,
- std::min<std::size_t>(max_size,
- streambuf_.max_size() - streambuf_.size()));
- if (bytes_available == 0)
+ std::size_t max_size, bytes_available;
+ switch (start)
{
- handler_(ec, total_transferred_);
- }
- else
- {
- stream_.async_read_some_at(offset_ + total_transferred_,
- streambuf_.prepare(bytes_available), *this);
+ case 1:
+ max_size = this->check_for_completion(ec, total_transferred_);
+ bytes_available = read_size_helper(streambuf_, max_size);
+ for (;;)
+ {
+ device_.async_read_some_at(offset_ + total_transferred_,
+ streambuf_.prepare(bytes_available), *this);
+ return; default:
+ total_transferred_ += bytes_transferred;
+ streambuf_.commit(bytes_transferred);
+ max_size = this->check_for_completion(ec, total_transferred_);
+ bytes_available = read_size_helper(streambuf_, max_size);
+ if ((!ec && bytes_transferred == 0) || bytes_available == 0)
+ break;
+ }
+
+ handler_(ec, static_cast<const std::size_t&>(total_transferred_));
}
}
//private:
- AsyncRandomAccessReadDevice& stream_;
+ AsyncRandomAccessReadDevice& device_;
boost::uint64_t offset_;
boost::asio::basic_streambuf<Allocator>& streambuf_;
std::size_t total_transferred_;
- CompletionCondition completion_condition_;
ReadHandler handler_;
};
template <typename AsyncRandomAccessReadDevice, typename Allocator,
typename CompletionCondition, typename ReadHandler>
inline void* asio_handler_allocate(std::size_t size,
- read_at_streambuf_handler<AsyncRandomAccessReadDevice, Allocator,
+ read_at_streambuf_op<AsyncRandomAccessReadDevice, Allocator,
CompletionCondition, ReadHandler>* this_handler)
{
return boost_asio_handler_alloc_helpers::allocate(
@@ -313,7 +363,7 @@ namespace detail
template <typename AsyncRandomAccessReadDevice, typename Allocator,
typename CompletionCondition, typename ReadHandler>
inline void asio_handler_deallocate(void* pointer, std::size_t size,
- read_at_streambuf_handler<AsyncRandomAccessReadDevice, Allocator,
+ read_at_streambuf_op<AsyncRandomAccessReadDevice, Allocator,
CompletionCondition, ReadHandler>* this_handler)
{
boost_asio_handler_alloc_helpers::deallocate(
@@ -323,7 +373,7 @@ namespace detail
template <typename Function, typename AsyncRandomAccessReadDevice,
typename Allocator, typename CompletionCondition, typename ReadHandler>
inline void asio_handler_invoke(const Function& function,
- read_at_streambuf_handler<AsyncRandomAccessReadDevice, Allocator,
+ read_at_streambuf_op<AsyncRandomAccessReadDevice, Allocator,
CompletionCondition, ReadHandler>* this_handler)
{
boost_asio_handler_invoke_helpers::invoke(
@@ -337,23 +387,10 @@ inline void async_read_at(AsyncRandomAccessReadDevice& d,
boost::uint64_t offset, boost::asio::basic_streambuf<Allocator>& b,
CompletionCondition completion_condition, ReadHandler handler)
{
- boost::system::error_code ec;
- std::size_t total_transferred = 0;
- std::size_t max_size = detail::adapt_completion_condition_result(
- completion_condition(ec, total_transferred));
- std::size_t bytes_available = std::min<std::size_t>(512,
- std::min<std::size_t>(max_size, b.max_size() - b.size()));
- if (bytes_available == 0)
- {
- d.get_io_service().post(detail::bind_handler(
- handler, ec, total_transferred));
- return;
- }
-
- d.async_read_some_at(offset, b.prepare(bytes_available),
- detail::read_at_streambuf_handler<AsyncRandomAccessReadDevice, Allocator,
- CompletionCondition, ReadHandler>(
- d, offset, b, completion_condition, handler));
+ detail::read_at_streambuf_op<AsyncRandomAccessReadDevice,
+ Allocator, CompletionCondition, ReadHandler>(
+ d, offset, b, completion_condition, handler)(
+ boost::system::error_code(), 0, 1);
}
template <typename AsyncRandomAccessReadDevice, typename Allocator,
@@ -372,4 +409,4 @@ inline void async_read_at(AsyncRandomAccessReadDevice& d,
#include <boost/asio/detail/pop_options.hpp>
-#endif // BOOST_ASIO_READ_AT_IPP
+#endif // BOOST_ASIO_IMPL_READ_AT_HPP
diff --git a/3rdParty/Boost/src/boost/asio/impl/read_until.hpp b/3rdParty/Boost/src/boost/asio/impl/read_until.hpp
new file mode 100644
index 0000000..73f8773
--- /dev/null
+++ b/3rdParty/Boost/src/boost/asio/impl/read_until.hpp
@@ -0,0 +1,904 @@
+//
+// impl/read_until.hpp
+// ~~~~~~~~~~~~~~~~~~~
+//
+// 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)
+//
+
+#ifndef BOOST_ASIO_IMPL_READ_UNTIL_HPP
+#define BOOST_ASIO_IMPL_READ_UNTIL_HPP
+
+#if defined(_MSC_VER) && (_MSC_VER >= 1200)
+# pragma once
+#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
+
+#include <algorithm>
+#include <string>
+#include <vector>
+#include <utility>
+#include <boost/limits.hpp>
+#include <boost/asio/buffer.hpp>
+#include <boost/asio/buffers_iterator.hpp>
+#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/throw_error.hpp>
+
+#include <boost/asio/detail/push_options.hpp>
+
+namespace boost {
+namespace asio {
+
+template <typename SyncReadStream, typename Allocator>
+inline std::size_t read_until(SyncReadStream& s,
+ boost::asio::basic_streambuf<Allocator>& b, char delim)
+{
+ boost::system::error_code ec;
+ std::size_t bytes_transferred = read_until(s, b, delim, ec);
+ boost::asio::detail::throw_error(ec);
+ return bytes_transferred;
+}
+
+template <typename SyncReadStream, typename Allocator>
+std::size_t read_until(SyncReadStream& s,
+ boost::asio::basic_streambuf<Allocator>& b, char delim,
+ boost::system::error_code& ec)
+{
+ std::size_t search_position = 0;
+ for (;;)
+ {
+ // Determine the range of the data to be searched.
+ typedef typename boost::asio::basic_streambuf<
+ Allocator>::const_buffers_type const_buffers_type;
+ 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 end = iterator::end(buffers);
+
+ // Look for a match.
+ iterator iter = std::find(start, end, delim);
+ if (iter != end)
+ {
+ // Found a match. We're done.
+ ec = boost::system::error_code();
+ return iter - begin + 1;
+ }
+ else
+ {
+ // No match. Next search can start with the new data.
+ search_position = end - begin;
+ }
+
+ // Check if buffer is full.
+ if (b.size() == b.max_size())
+ {
+ ec = error::not_found;
+ return 0;
+ }
+
+ // Need more data.
+ std::size_t bytes_to_read = read_size_helper(b, 65536);
+ b.commit(s.read_some(b.prepare(bytes_to_read), ec));
+ if (ec)
+ return 0;
+ }
+}
+
+template <typename SyncReadStream, typename Allocator>
+inline std::size_t read_until(SyncReadStream& s,
+ boost::asio::basic_streambuf<Allocator>& b, const std::string& delim)
+{
+ boost::system::error_code ec;
+ std::size_t bytes_transferred = read_until(s, b, delim, ec);
+ boost::asio::detail::throw_error(ec);
+ return bytes_transferred;
+}
+
+namespace detail
+{
+ // Algorithm that finds a subsequence of equal values in a sequence. Returns
+ // (iterator,true) if a full match was found, in which case the iterator
+ // points to the beginning of the match. Returns (iterator,false) if a
+ // partial match was found at the end of the first sequence, in which case
+ // the iterator points to the beginning of the partial match. Returns
+ // (last1,false) if no full or partial match was found.
+ template <typename Iterator1, typename Iterator2>
+ std::pair<Iterator1, bool> partial_search(
+ Iterator1 first1, Iterator1 last1, Iterator2 first2, Iterator2 last2)
+ {
+ for (Iterator1 iter1 = first1; iter1 != last1; ++iter1)
+ {
+ Iterator1 test_iter1 = iter1;
+ Iterator2 test_iter2 = first2;
+ for (;; ++test_iter1, ++test_iter2)
+ {
+ if (test_iter2 == last2)
+ return std::make_pair(iter1, true);
+ if (test_iter1 == last1)
+ {
+ if (test_iter2 != first2)
+ return std::make_pair(iter1, false);
+ else
+ break;
+ }
+ if (*test_iter1 != *test_iter2)
+ break;
+ }
+ }
+ return std::make_pair(last1, false);
+ }
+} // namespace detail
+
+template <typename SyncReadStream, typename Allocator>
+std::size_t read_until(SyncReadStream& s,
+ boost::asio::basic_streambuf<Allocator>& b, const std::string& delim,
+ boost::system::error_code& ec)
+{
+ std::size_t search_position = 0;
+ for (;;)
+ {
+ // Determine the range of the data to be searched.
+ typedef typename boost::asio::basic_streambuf<
+ Allocator>::const_buffers_type const_buffers_type;
+ 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 end = iterator::end(buffers);
+
+ // Look for a match.
+ std::pair<iterator, bool> result = detail::partial_search(
+ start, end, delim.begin(), delim.end());
+ if (result.first != end)
+ {
+ if (result.second)
+ {
+ // Full match. We're done.
+ ec = boost::system::error_code();
+ return result.first - begin + delim.length();
+ }
+ else
+ {
+ // Partial match. Next search needs to start from beginning of match.
+ search_position = result.first - begin;
+ }
+ }
+ else
+ {
+ // No match. Next search can start with the new data.
+ search_position = end - begin;
+ }
+
+ // Check if buffer is full.
+ if (b.size() == b.max_size())
+ {
+ ec = error::not_found;
+ return 0;
+ }
+
+ // Need more data.
+ std::size_t bytes_to_read = read_size_helper(b, 65536);
+ b.commit(s.read_some(b.prepare(bytes_to_read), ec));
+ if (ec)
+ return 0;
+ }
+}
+
+template <typename SyncReadStream, typename Allocator>
+inline std::size_t read_until(SyncReadStream& s,
+ boost::asio::basic_streambuf<Allocator>& b, const boost::regex& expr)
+{
+ boost::system::error_code ec;
+ std::size_t bytes_transferred = read_until(s, b, expr, ec);
+ boost::asio::detail::throw_error(ec);
+ return bytes_transferred;
+}
+
+template <typename SyncReadStream, typename Allocator>
+std::size_t read_until(SyncReadStream& s,
+ boost::asio::basic_streambuf<Allocator>& b, const boost::regex& expr,
+ boost::system::error_code& ec)
+{
+ std::size_t search_position = 0;
+ for (;;)
+ {
+ // Determine the range of the data to be searched.
+ typedef typename boost::asio::basic_streambuf<
+ Allocator>::const_buffers_type const_buffers_type;
+ 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 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,
+ boost::match_default | boost::match_partial))
+ {
+ if (match_results[0].matched)
+ {
+ // Full match. We're done.
+ ec = boost::system::error_code();
+ return match_results[0].second - begin;
+ }
+ else
+ {
+ // Partial match. Next search needs to start from beginning of match.
+ search_position = match_results[0].first - begin;
+ }
+ }
+ else
+ {
+ // No match. Next search can start with the new data.
+ search_position = end - begin;
+ }
+
+ // Check if buffer is full.
+ if (b.size() == b.max_size())
+ {
+ ec = error::not_found;
+ return 0;
+ }
+
+ // Need more data.
+ std::size_t bytes_to_read = read_size_helper(b, 65536);
+ b.commit(s.read_some(b.prepare(bytes_to_read), ec));
+ if (ec)
+ return 0;
+ }
+}
+
+template <typename SyncReadStream, typename Allocator, typename MatchCondition>
+std::size_t read_until(SyncReadStream& s,
+ boost::asio::basic_streambuf<Allocator>& b,
+ MatchCondition match_condition, boost::system::error_code& ec,
+ typename boost::enable_if<is_match_condition<MatchCondition> >::type*)
+{
+ std::size_t search_position = 0;
+ for (;;)
+ {
+ // Determine the range of the data to be searched.
+ typedef typename boost::asio::basic_streambuf<
+ Allocator>::const_buffers_type const_buffers_type;
+ 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 end = iterator::end(buffers);
+
+ // Look for a match.
+ std::pair<iterator, bool> result = match_condition(start, end);
+ if (result.second)
+ {
+ // Full match. We're done.
+ ec = boost::system::error_code();
+ return result.first - begin;
+ }
+ else if (result.first != end)
+ {
+ // Partial match. Next search needs to start from beginning of match.
+ search_position = result.first - begin;
+ }
+ else
+ {
+ // No match. Next search can start with the new data.
+ search_position = end - begin;
+ }
+
+ // Check if buffer is full.
+ if (b.size() == b.max_size())
+ {
+ ec = error::not_found;
+ return 0;
+ }
+
+ // Need more data.
+ std::size_t bytes_to_read = read_size_helper(b, 65536);
+ b.commit(s.read_some(b.prepare(bytes_to_read), ec));
+ if (ec)
+ return 0;
+ }
+}
+
+template <typename SyncReadStream, typename Allocator, typename MatchCondition>
+inline std::size_t read_until(SyncReadStream& s,
+ boost::asio::basic_streambuf<Allocator>& b, MatchCondition match_condition,
+ typename boost::enable_if<is_match_condition<MatchCondition> >::type*)
+{
+ boost::system::error_code ec;
+ std::size_t bytes_transferred = read_until(s, b, match_condition, ec);
+ boost::asio::detail::throw_error(ec);
+ return bytes_transferred;
+}
+
+namespace detail
+{
+ template <typename AsyncReadStream, typename Allocator, typename ReadHandler>
+ class read_until_delim_op
+ {
+ public:
+ read_until_delim_op(AsyncReadStream& stream,
+ boost::asio::basic_streambuf<Allocator>& streambuf,
+ char delim, ReadHandler handler)
+ : stream_(stream),
+ streambuf_(streambuf),
+ delim_(delim),
+ search_position_(0),
+ handler_(handler)
+ {
+ }
+
+ void operator()(const boost::system::error_code& ec,
+ std::size_t bytes_transferred, int start = 0)
+ {
+ const std::size_t not_found = (std::numeric_limits<std::size_t>::max)();
+ std::size_t bytes_to_read;
+ switch (start)
+ {
+ case 1:
+ for (;;)
+ {
+ {
+ // Determine the range of the data to be searched.
+ typedef typename boost::asio::basic_streambuf<
+ Allocator>::const_buffers_type const_buffers_type;
+ 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 end = iterator::end(buffers);
+
+ // Look for a match.
+ iterator iter = std::find(start, end, delim_);
+ if (iter != end)
+ {
+ // Found a match. We're done.
+ search_position_ = iter - begin + 1;
+ bytes_to_read = 0;
+ }
+
+ // No match yet. Check if buffer is full.
+ else if (streambuf_.size() == streambuf_.max_size())
+ {
+ search_position_ = not_found;
+ bytes_to_read = 0;
+ }
+
+ // Need to read some more data.
+ else
+ {
+ // Next search can start with the new data.
+ search_position_ = end - begin;
+ bytes_to_read = read_size_helper(streambuf_, 65536);
+ }
+ }
+
+ // Check if we're done.
+ if (!start && bytes_to_read == 0)
+ break;
+
+ // Start a new asynchronous read operation to obtain more data.
+ stream_.async_read_some(streambuf_.prepare(bytes_to_read), *this);
+ return; default:
+ streambuf_.commit(bytes_transferred);
+ if (ec || bytes_transferred == 0)
+ break;
+ }
+
+ const boost::system::error_code result_ec =
+ (search_position_ == not_found)
+ ? error::not_found : ec;
+
+ const std::size_t result_n =
+ (ec || search_position_ == not_found)
+ ? 0 : search_position_;
+
+ handler_(result_ec, result_n);
+ }
+ }
+
+ //private:
+ AsyncReadStream& stream_;
+ boost::asio::basic_streambuf<Allocator>& streambuf_;
+ char delim_;
+ std::size_t search_position_;
+ ReadHandler handler_;
+ };
+
+ template <typename AsyncReadStream, typename Allocator, typename ReadHandler>
+ inline void* asio_handler_allocate(std::size_t size,
+ read_until_delim_op<AsyncReadStream,
+ Allocator, ReadHandler>* this_handler)
+ {
+ return boost_asio_handler_alloc_helpers::allocate(
+ size, this_handler->handler_);
+ }
+
+ template <typename AsyncReadStream, typename Allocator, typename ReadHandler>
+ inline void asio_handler_deallocate(void* pointer, std::size_t size,
+ read_until_delim_op<AsyncReadStream,
+ Allocator, ReadHandler>* this_handler)
+ {
+ boost_asio_handler_alloc_helpers::deallocate(
+ pointer, size, 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)
+ {
+ boost_asio_handler_invoke_helpers::invoke(
+ function, this_handler->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)
+{
+ detail::read_until_delim_op<
+ AsyncReadStream, Allocator, ReadHandler>(
+ s, b, delim, handler)(
+ boost::system::error_code(), 0, 1);
+}
+
+namespace detail
+{
+ template <typename AsyncReadStream, typename Allocator, typename ReadHandler>
+ class read_until_delim_string_op
+ {
+ public:
+ read_until_delim_string_op(AsyncReadStream& stream,
+ boost::asio::basic_streambuf<Allocator>& streambuf,
+ const std::string& delim, ReadHandler handler)
+ : stream_(stream),
+ streambuf_(streambuf),
+ delim_(delim),
+ search_position_(0),
+ handler_(handler)
+ {
+ }
+
+ void operator()(const boost::system::error_code& ec,
+ std::size_t bytes_transferred, int start = 0)
+ {
+ const std::size_t not_found = (std::numeric_limits<std::size_t>::max)();
+ std::size_t bytes_to_read;
+ switch (start)
+ {
+ case 1:
+ for (;;)
+ {
+ {
+ // Determine the range of the data to be searched.
+ typedef typename boost::asio::basic_streambuf<
+ Allocator>::const_buffers_type const_buffers_type;
+ 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 end = iterator::end(buffers);
+
+ // Look for a match.
+ std::pair<iterator, bool> result = detail::partial_search(
+ start, end, delim_.begin(), delim_.end());
+ if (result.first != end && result.second)
+ {
+ // Full match. We're done.
+ search_position_ = result.first - begin + delim_.length();
+ bytes_to_read = 0;
+ }
+
+ // No match yet. Check if buffer is full.
+ else if (streambuf_.size() == streambuf_.max_size())
+ {
+ search_position_ = not_found;
+ bytes_to_read = 0;
+ }
+
+ // Need to read some more data.
+ else
+ {
+ if (result.first != end)
+ {
+ // Partial match. Next search needs to start from beginning of
+ // match.
+ search_position_ = result.first - begin;
+ }
+ else
+ {
+ // Next search can start with the new data.
+ search_position_ = end - begin;
+ }
+
+ bytes_to_read = read_size_helper(streambuf_, 65536);
+ }
+ }
+
+ // Check if we're done.
+ if (!start && bytes_to_read == 0)
+ break;
+
+ // Start a new asynchronous read operation to obtain more data.
+ stream_.async_read_some(streambuf_.prepare(bytes_to_read), *this);
+ return; default:
+ streambuf_.commit(bytes_transferred);
+ if (ec || bytes_transferred == 0)
+ break;
+ }
+
+ const boost::system::error_code result_ec =
+ (search_position_ == not_found)
+ ? error::not_found : ec;
+
+ const std::size_t result_n =
+ (ec || search_position_ == not_found)
+ ? 0 : search_position_;
+
+ handler_(result_ec, result_n);
+ }
+ }
+
+ //private:
+ AsyncReadStream& stream_;
+ boost::asio::basic_streambuf<Allocator>& streambuf_;
+ std::string delim_;
+ std::size_t search_position_;
+ ReadHandler handler_;
+ };
+
+ template <typename AsyncReadStream, typename Allocator, typename ReadHandler>
+ inline void* asio_handler_allocate(std::size_t size,
+ read_until_delim_string_op<AsyncReadStream,
+ Allocator, ReadHandler>* this_handler)
+ {
+ return boost_asio_handler_alloc_helpers::allocate(
+ size, this_handler->handler_);
+ }
+
+ template <typename AsyncReadStream, typename Allocator, typename ReadHandler>
+ inline void asio_handler_deallocate(void* pointer, std::size_t size,
+ read_until_delim_string_op<AsyncReadStream,
+ Allocator, ReadHandler>* this_handler)
+ {
+ boost_asio_handler_alloc_helpers::deallocate(
+ pointer, size, 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)
+ {
+ boost_asio_handler_invoke_helpers::invoke(
+ function, this_handler->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)
+{
+ detail::read_until_delim_string_op<
+ AsyncReadStream, Allocator, ReadHandler>(
+ s, b, delim, handler)(
+ boost::system::error_code(), 0, 1);
+}
+
+namespace detail
+{
+ template <typename AsyncReadStream, typename Allocator,
+ typename RegEx, typename ReadHandler>
+ class read_until_expr_op
+ {
+ public:
+ read_until_expr_op(AsyncReadStream& stream,
+ boost::asio::basic_streambuf<Allocator>& streambuf,
+ const boost::regex& expr, ReadHandler handler)
+ : stream_(stream),
+ streambuf_(streambuf),
+ expr_(expr),
+ search_position_(0),
+ handler_(handler)
+ {
+ }
+
+ void operator()(const boost::system::error_code& ec,
+ std::size_t bytes_transferred, int start = 0)
+ {
+ const std::size_t not_found = (std::numeric_limits<std::size_t>::max)();
+ std::size_t bytes_to_read;
+ switch (start)
+ {
+ case 1:
+ for (;;)
+ {
+ {
+ // Determine the range of the data to be searched.
+ typedef typename boost::asio::basic_streambuf<
+ Allocator>::const_buffers_type const_buffers_type;
+ 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 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_,
+ boost::match_default | boost::match_partial);
+ if (match && match_results[0].matched)
+ {
+ // Full match. We're done.
+ search_position_ = match_results[0].second - begin;
+ bytes_to_read = 0;
+ }
+
+ // No match yet. Check if buffer is full.
+ else if (streambuf_.size() == streambuf_.max_size())
+ {
+ search_position_ = not_found;
+ bytes_to_read = 0;
+ }
+
+ // Need to read some more data.
+ else
+ {
+ if (match)
+ {
+ // Partial match. Next search needs to start from beginning of
+ // match.
+ search_position_ = match_results[0].first - begin;
+ }
+ else
+ {
+ // Next search can start with the new data.
+ search_position_ = end - begin;
+ }
+
+ bytes_to_read = read_size_helper(streambuf_, 65536);
+ }
+ }
+
+ // Check if we're done.
+ if (!start && bytes_to_read == 0)
+ break;
+
+ // Start a new asynchronous read operation to obtain more data.
+ stream_.async_read_some(streambuf_.prepare(bytes_to_read), *this);
+ return; default:
+ streambuf_.commit(bytes_transferred);
+ if (ec || bytes_transferred == 0)
+ break;
+ }
+
+ const boost::system::error_code result_ec =
+ (search_position_ == not_found)
+ ? error::not_found : ec;
+
+ const std::size_t result_n =
+ (ec || search_position_ == not_found)
+ ? 0 : search_position_;
+
+ handler_(result_ec, result_n);
+ }
+ }
+
+ //private:
+ AsyncReadStream& stream_;
+ boost::asio::basic_streambuf<Allocator>& streambuf_;
+ RegEx expr_;
+ std::size_t search_position_;
+ ReadHandler handler_;
+ };
+
+ template <typename AsyncReadStream, typename Allocator,
+ typename RegEx, typename ReadHandler>
+ inline void* asio_handler_allocate(std::size_t size,
+ read_until_expr_op<AsyncReadStream,
+ Allocator, RegEx, ReadHandler>* this_handler)
+ {
+ return boost_asio_handler_alloc_helpers::allocate(
+ size, this_handler->handler_);
+ }
+
+ template <typename AsyncReadStream, typename Allocator,
+ typename RegEx, typename ReadHandler>
+ inline void asio_handler_deallocate(void* pointer, std::size_t size,
+ read_until_expr_op<AsyncReadStream,
+ Allocator, RegEx, ReadHandler>* this_handler)
+ {
+ boost_asio_handler_alloc_helpers::deallocate(
+ pointer, size, 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)
+ {
+ boost_asio_handler_invoke_helpers::invoke(
+ function, this_handler->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)
+{
+ detail::read_until_expr_op<AsyncReadStream,
+ Allocator, boost::regex, ReadHandler>(
+ s, b, expr, handler)(
+ boost::system::error_code(), 0, 1);
+}
+
+namespace detail
+{
+ template <typename AsyncReadStream, typename Allocator,
+ typename MatchCondition, typename ReadHandler>
+ class read_until_match_op
+ {
+ public:
+ read_until_match_op(AsyncReadStream& stream,
+ boost::asio::basic_streambuf<Allocator>& streambuf,
+ MatchCondition match_condition, ReadHandler handler)
+ : stream_(stream),
+ streambuf_(streambuf),
+ match_condition_(match_condition),
+ search_position_(0),
+ handler_(handler)
+ {
+ }
+
+ void operator()(const boost::system::error_code& ec,
+ std::size_t bytes_transferred, int start = 0)
+ {
+ const std::size_t not_found = (std::numeric_limits<std::size_t>::max)();
+ std::size_t bytes_to_read;
+ switch (start)
+ {
+ case 1:
+ for (;;)
+ {
+ {
+ // Determine the range of the data to be searched.
+ typedef typename boost::asio::basic_streambuf<
+ Allocator>::const_buffers_type const_buffers_type;
+ 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 end = iterator::end(buffers);
+
+ // Look for a match.
+ std::pair<iterator, bool> result = match_condition_(start, end);
+ if (result.second)
+ {
+ // Full match. We're done.
+ search_position_ = result.first - begin;
+ bytes_to_read = 0;
+ }
+
+ // No match yet. Check if buffer is full.
+ else if (streambuf_.size() == streambuf_.max_size())
+ {
+ search_position_ = not_found;
+ bytes_to_read = 0;
+ }
+
+ // Need to read some more data.
+ else
+ {
+ if (result.first != end)
+ {
+ // Partial match. Next search needs to start from beginning of
+ // match.
+ search_position_ = result.first - begin;
+ }
+ else
+ {
+ // Next search can start with the new data.
+ search_position_ = end - begin;
+ }
+
+ bytes_to_read = read_size_helper(streambuf_, 65536);
+ }
+ }
+
+ // Check if we're done.
+ if (!start && bytes_to_read == 0)
+ break;
+
+ // Start a new asynchronous read operation to obtain more data.
+ stream_.async_read_some(streambuf_.prepare(bytes_to_read), *this);
+ return; default:
+ streambuf_.commit(bytes_transferred);
+ if (ec || bytes_transferred == 0)
+ break;
+ }
+
+ const boost::system::error_code result_ec =
+ (search_position_ == not_found)
+ ? error::not_found : ec;
+
+ const std::size_t result_n =
+ (ec || search_position_ == not_found)
+ ? 0 : search_position_;
+
+ handler_(result_ec, result_n);
+ }
+ }
+
+ //private:
+ AsyncReadStream& stream_;
+ boost::asio::basic_streambuf<Allocator>& streambuf_;
+ MatchCondition match_condition_;
+ std::size_t search_position_;
+ ReadHandler handler_;
+ };
+
+ template <typename AsyncReadStream, typename Allocator,
+ typename MatchCondition, typename ReadHandler>
+ inline void* asio_handler_allocate(std::size_t size,
+ read_until_match_op<AsyncReadStream,
+ Allocator, MatchCondition, ReadHandler>* this_handler)
+ {
+ return boost_asio_handler_alloc_helpers::allocate(
+ size, this_handler->handler_);
+ }
+
+ template <typename AsyncReadStream, typename Allocator,
+ typename MatchCondition, typename ReadHandler>
+ inline void asio_handler_deallocate(void* pointer, std::size_t size,
+ read_until_match_op<AsyncReadStream,
+ Allocator, MatchCondition, ReadHandler>* this_handler)
+ {
+ boost_asio_handler_alloc_helpers::deallocate(
+ pointer, size, 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)
+ {
+ boost_asio_handler_invoke_helpers::invoke(
+ function, this_handler->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,
+ 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);
+}
+
+} // namespace asio
+} // namespace boost
+
+#include <boost/asio/detail/pop_options.hpp>
+
+#endif // BOOST_ASIO_IMPL_READ_UNTIL_HPP
diff --git a/3rdParty/Boost/src/boost/asio/impl/read_until.ipp b/3rdParty/Boost/src/boost/asio/impl/read_until.ipp
deleted file mode 100644
index 0ee0de0..0000000
--- a/3rdParty/Boost/src/boost/asio/impl/read_until.ipp
+++ /dev/null
@@ -1,989 +0,0 @@
-//
-// read_until.ipp
-// ~~~~~~~~~~~~~~
-//
-// 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)
-//
-
-#ifndef BOOST_ASIO_READ_UNTIL_IPP
-#define BOOST_ASIO_READ_UNTIL_IPP
-
-#if defined(_MSC_VER) && (_MSC_VER >= 1200)
-# pragma once
-#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
-
-#include <boost/asio/detail/push_options.hpp>
-
-#include <boost/asio/detail/push_options.hpp>
-#include <algorithm>
-#include <string>
-#include <utility>
-#include <boost/limits.hpp>
-#include <boost/asio/detail/pop_options.hpp>
-
-#include <boost/asio/buffer.hpp>
-#include <boost/asio/buffers_iterator.hpp>
-#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/throw_error.hpp>
-
-namespace boost {
-namespace asio {
-
-template <typename SyncReadStream, typename Allocator>
-inline std::size_t read_until(SyncReadStream& s,
- boost::asio::basic_streambuf<Allocator>& b, char delim)
-{
- boost::system::error_code ec;
- std::size_t bytes_transferred = read_until(s, b, delim, ec);
- boost::asio::detail::throw_error(ec);
- return bytes_transferred;
-}
-
-template <typename SyncReadStream, typename Allocator>
-std::size_t read_until(SyncReadStream& s,
- boost::asio::basic_streambuf<Allocator>& b, char delim,
- boost::system::error_code& ec)
-{
- std::size_t next_search_start = 0;
- for (;;)
- {
- // Determine the range of the data to be searched.
- typedef typename boost::asio::basic_streambuf<
- Allocator>::const_buffers_type const_buffers_type;
- typedef boost::asio::buffers_iterator<const_buffers_type> iterator;
- const_buffers_type buffers = b.data();
- iterator begin = iterator::begin(buffers);
- iterator start = begin + next_search_start;
- iterator end = iterator::end(buffers);
-
- // Look for a match.
- iterator iter = std::find(start, end, delim);
- if (iter != end)
- {
- // Found a match. We're done.
- ec = boost::system::error_code();
- return iter - begin + 1;
- }
- else
- {
- // No match. Next search can start with the new data.
- next_search_start = end - begin;
- }
-
- // Check if buffer is full.
- if (b.size() == b.max_size())
- {
- ec = error::not_found;
- return 0;
- }
-
- // Need more data.
- std::size_t bytes_available =
- std::min<std::size_t>(512, b.max_size() - b.size());
- b.commit(s.read_some(b.prepare(bytes_available), ec));
- if (ec)
- return 0;
- }
-}
-
-template <typename SyncReadStream, typename Allocator>
-inline std::size_t read_until(SyncReadStream& s,
- boost::asio::basic_streambuf<Allocator>& b, const std::string& delim)
-{
- boost::system::error_code ec;
- std::size_t bytes_transferred = read_until(s, b, delim, ec);
- boost::asio::detail::throw_error(ec);
- return bytes_transferred;
-}
-
-namespace detail
-{
- // Algorithm that finds a subsequence of equal values in a sequence. Returns
- // (iterator,true) if a full match was found, in which case the iterator
- // points to the beginning of the match. Returns (iterator,false) if a
- // partial match was found at the end of the first sequence, in which case
- // the iterator points to the beginning of the partial match. Returns
- // (last1,false) if no full or partial match was found.
- template <typename Iterator1, typename Iterator2>
- std::pair<Iterator1, bool> partial_search(
- Iterator1 first1, Iterator1 last1, Iterator2 first2, Iterator2 last2)
- {
- for (Iterator1 iter1 = first1; iter1 != last1; ++iter1)
- {
- Iterator1 test_iter1 = iter1;
- Iterator2 test_iter2 = first2;
- for (;; ++test_iter1, ++test_iter2)
- {
- if (test_iter2 == last2)
- return std::make_pair(iter1, true);
- if (test_iter1 == last1)
- {
- if (test_iter2 != first2)
- return std::make_pair(iter1, false);
- else
- break;
- }
- if (*test_iter1 != *test_iter2)
- break;
- }
- }
- return std::make_pair(last1, false);
- }
-} // namespace detail
-
-template <typename SyncReadStream, typename Allocator>
-std::size_t read_until(SyncReadStream& s,
- boost::asio::basic_streambuf<Allocator>& b, const std::string& delim,
- boost::system::error_code& ec)
-{
- std::size_t next_search_start = 0;
- for (;;)
- {
- // Determine the range of the data to be searched.
- typedef typename boost::asio::basic_streambuf<
- Allocator>::const_buffers_type const_buffers_type;
- typedef boost::asio::buffers_iterator<const_buffers_type> iterator;
- const_buffers_type buffers = b.data();
- iterator begin = iterator::begin(buffers);
- iterator start = begin + next_search_start;
- iterator end = iterator::end(buffers);
-
- // Look for a match.
- std::pair<iterator, bool> result = boost::asio::detail::partial_search(
- start, end, delim.begin(), delim.end());
- if (result.first != end)
- {
- if (result.second)
- {
- // Full match. We're done.
- ec = boost::system::error_code();
- return result.first - begin + delim.length();
- }
- else
- {
- // Partial match. Next search needs to start from beginning of match.
- next_search_start = result.first - begin;
- }
- }
- else
- {
- // No match. Next search can start with the new data.
- next_search_start = end - begin;
- }
-
- // Check if buffer is full.
- if (b.size() == b.max_size())
- {
- ec = error::not_found;
- return 0;
- }
-
- // Need more data.
- std::size_t bytes_available =
- std::min<std::size_t>(512, b.max_size() - b.size());
- b.commit(s.read_some(b.prepare(bytes_available), ec));
- if (ec)
- return 0;
- }
-}
-
-template <typename SyncReadStream, typename Allocator>
-inline std::size_t read_until(SyncReadStream& s,
- boost::asio::basic_streambuf<Allocator>& b, const boost::regex& expr)
-{
- boost::system::error_code ec;
- std::size_t bytes_transferred = read_until(s, b, expr, ec);
- boost::asio::detail::throw_error(ec);
- return bytes_transferred;
-}
-
-template <typename SyncReadStream, typename Allocator>
-std::size_t read_until(SyncReadStream& s,
- boost::asio::basic_streambuf<Allocator>& b, const boost::regex& expr,
- boost::system::error_code& ec)
-{
- std::size_t next_search_start = 0;
- for (;;)
- {
- // Determine the range of the data to be searched.
- typedef typename boost::asio::basic_streambuf<
- Allocator>::const_buffers_type const_buffers_type;
- typedef boost::asio::buffers_iterator<const_buffers_type> iterator;
- const_buffers_type buffers = b.data();
- iterator begin = iterator::begin(buffers);
- iterator start = begin + next_search_start;
- iterator end = iterator::end(buffers);
-
- // Look for a match.
- boost::match_results<iterator> match_results;
- if (boost::regex_search(start, end, match_results, expr,
- boost::match_default | boost::match_partial))
- {
- if (match_results[0].matched)
- {
- // Full match. We're done.
- ec = boost::system::error_code();
- return match_results[0].second - begin;
- }
- else
- {
- // Partial match. Next search needs to start from beginning of match.
- next_search_start = match_results[0].first - begin;
- }
- }
- else
- {
- // No match. Next search can start with the new data.
- next_search_start = end - begin;
- }
-
- // Check if buffer is full.
- if (b.size() == b.max_size())
- {
- ec = error::not_found;
- return 0;
- }
-
- // Need more data.
- std::size_t bytes_available =
- std::min<std::size_t>(512, b.max_size() - b.size());
- b.commit(s.read_some(b.prepare(bytes_available), ec));
- if (ec)
- return 0;
- }
-}
-
-template <typename SyncReadStream, typename Allocator, typename MatchCondition>
-std::size_t read_until(SyncReadStream& s,
- boost::asio::basic_streambuf<Allocator>& b,
- MatchCondition match_condition, boost::system::error_code& ec,
- typename boost::enable_if<is_match_condition<MatchCondition> >::type*)
-{
- std::size_t next_search_start = 0;
- for (;;)
- {
- // Determine the range of the data to be searched.
- typedef typename boost::asio::basic_streambuf<
- Allocator>::const_buffers_type const_buffers_type;
- typedef boost::asio::buffers_iterator<const_buffers_type> iterator;
- const_buffers_type buffers = b.data();
- iterator begin = iterator::begin(buffers);
- iterator start = begin + next_search_start;
- iterator end = iterator::end(buffers);
-
- // Look for a match.
- std::pair<iterator, bool> result = match_condition(start, end);
- if (result.second)
- {
- // Full match. We're done.
- ec = boost::system::error_code();
- return result.first - begin;
- }
- else if (result.first != end)
- {
- // Partial match. Next search needs to start from beginning of match.
- next_search_start = result.first - begin;
- }
- else
- {
- // No match. Next search can start with the new data.
- next_search_start = end - begin;
- }
-
- // Check if buffer is full.
- if (b.size() == b.max_size())
- {
- ec = error::not_found;
- return 0;
- }
-
- // Need more data.
- std::size_t bytes_available =
- std::min<std::size_t>(512, b.max_size() - b.size());
- b.commit(s.read_some(b.prepare(bytes_available), ec));
- if (ec)
- return 0;
- }
-}
-
-template <typename SyncReadStream, typename Allocator, typename MatchCondition>
-inline std::size_t read_until(SyncReadStream& s,
- boost::asio::basic_streambuf<Allocator>& b, MatchCondition match_condition,
- typename boost::enable_if<is_match_condition<MatchCondition> >::type*)
-{
- boost::system::error_code ec;
- std::size_t bytes_transferred = read_until(s, b, match_condition, ec);
- boost::asio::detail::throw_error(ec);
- return bytes_transferred;
-}
-
-namespace detail
-{
- template <typename AsyncReadStream, typename Allocator, typename ReadHandler>
- class read_until_delim_handler
- {
- public:
- read_until_delim_handler(AsyncReadStream& stream,
- boost::asio::basic_streambuf<Allocator>& streambuf, char delim,
- std::size_t next_search_start, ReadHandler handler)
- : stream_(stream),
- streambuf_(streambuf),
- delim_(delim),
- next_search_start_(next_search_start),
- handler_(handler)
- {
- }
-
- void operator()(const boost::system::error_code& ec,
- std::size_t bytes_transferred)
- {
- // Check for errors.
- if (ec)
- {
- std::size_t bytes = 0;
- handler_(ec, bytes);
- return;
- }
-
- // Commit received data to streambuf's get area.
- streambuf_.commit(bytes_transferred);
-
- // Determine the range of the data to be searched.
- typedef typename boost::asio::basic_streambuf<
- Allocator>::const_buffers_type const_buffers_type;
- typedef boost::asio::buffers_iterator<const_buffers_type> iterator;
- const_buffers_type buffers = streambuf_.data();
- iterator begin = iterator::begin(buffers);
- iterator start = begin + next_search_start_;
- iterator end = iterator::end(buffers);
-
- // Look for a match.
- iterator iter = std::find(start, end, delim_);
- if (iter != end)
- {
- // Found a match. We're done.
- std::size_t bytes = iter - begin + 1;
- handler_(ec, bytes);
- return;
- }
-
- // No match. Check if buffer is full.
- if (streambuf_.size() == streambuf_.max_size())
- {
- std::size_t bytes = 0;
- boost::system::error_code ec(error::not_found);
- handler_(ec, bytes);
- return;
- }
-
- // Next search can start with the new data.
- next_search_start_ = end - begin;
-
- // Start a new asynchronous read operation to obtain more data.
- std::size_t bytes_available =
- std::min<std::size_t>(512, streambuf_.max_size() - streambuf_.size());
- stream_.async_read_some(streambuf_.prepare(bytes_available), *this);
- }
-
- //private:
- AsyncReadStream& stream_;
- boost::asio::basic_streambuf<Allocator>& streambuf_;
- char delim_;
- std::size_t next_search_start_;
- ReadHandler handler_;
- };
-
- template <typename AsyncReadStream, typename Allocator, typename ReadHandler>
- inline void* asio_handler_allocate(std::size_t size,
- read_until_delim_handler<AsyncReadStream,
- Allocator, ReadHandler>* this_handler)
- {
- return boost_asio_handler_alloc_helpers::allocate(
- size, this_handler->handler_);
- }
-
- template <typename AsyncReadStream, typename Allocator, typename ReadHandler>
- inline void asio_handler_deallocate(void* pointer, std::size_t size,
- read_until_delim_handler<AsyncReadStream,
- Allocator, ReadHandler>* this_handler)
- {
- boost_asio_handler_alloc_helpers::deallocate(
- pointer, size, this_handler->handler_);
- }
-
- template <typename Function, typename AsyncReadStream, typename Allocator,
- typename ReadHandler>
- inline void asio_handler_invoke(const Function& function,
- read_until_delim_handler<AsyncReadStream,
- Allocator, ReadHandler>* this_handler)
- {
- boost_asio_handler_invoke_helpers::invoke(
- function, this_handler->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)
-{
- // Determine the range of the data to be searched.
- typedef typename boost::asio::basic_streambuf<
- Allocator>::const_buffers_type const_buffers_type;
- typedef boost::asio::buffers_iterator<const_buffers_type> iterator;
- const_buffers_type buffers = b.data();
- iterator begin = iterator::begin(buffers);
- iterator end = iterator::end(buffers);
-
- // Look for a match.
- iterator iter = std::find(begin, end, delim);
- if (iter != end)
- {
- // Found a match. We're done.
- boost::system::error_code ec;
- std::size_t bytes = iter - begin + 1;
- s.get_io_service().post(detail::bind_handler(handler, ec, bytes));
- return;
- }
-
- // No match. Check if buffer is full.
- if (b.size() == b.max_size())
- {
- boost::system::error_code ec(error::not_found);
- s.get_io_service().post(detail::bind_handler(handler, ec, 0));
- return;
- }
-
- // Start a new asynchronous read operation to obtain more data.
- std::size_t bytes_available =
- std::min<std::size_t>(512, b.max_size() - b.size());
- s.async_read_some(b.prepare(bytes_available),
- detail::read_until_delim_handler<AsyncReadStream, Allocator, ReadHandler>(
- s, b, delim, end - begin, handler));
-}
-
-namespace detail
-{
- template <typename AsyncReadStream, typename Allocator, typename ReadHandler>
- class read_until_delim_string_handler
- {
- public:
- read_until_delim_string_handler(AsyncReadStream& stream,
- boost::asio::basic_streambuf<Allocator>& streambuf,
- const std::string& delim, std::size_t next_search_start,
- ReadHandler handler)
- : stream_(stream),
- streambuf_(streambuf),
- delim_(delim),
- next_search_start_(next_search_start),
- handler_(handler)
- {
- }
-
- void operator()(const boost::system::error_code& ec,
- std::size_t bytes_transferred)
- {
- // Check for errors.
- if (ec)
- {
- std::size_t bytes = 0;
- handler_(ec, bytes);
- return;
- }
-
- // Commit received data to streambuf's get area.
- streambuf_.commit(bytes_transferred);
-
- // Determine the range of the data to be searched.
- typedef typename boost::asio::basic_streambuf<
- Allocator>::const_buffers_type const_buffers_type;
- typedef boost::asio::buffers_iterator<const_buffers_type> iterator;
- const_buffers_type buffers = streambuf_.data();
- iterator begin = iterator::begin(buffers);
- iterator start = begin + next_search_start_;
- iterator end = iterator::end(buffers);
-
- // Look for a match.
- std::pair<iterator, bool> result = boost::asio::detail::partial_search(
- start, end, delim_.begin(), delim_.end());
- if (result.first != end)
- {
- if (result.second)
- {
- // Full match. We're done.
- std::size_t bytes = result.first - begin + delim_.length();
- handler_(ec, bytes);
- return;
- }
- else
- {
- // Partial match. Next search needs to start from beginning of match.
- next_search_start_ = result.first - begin;
- }
- }
- else
- {
- // No match. Next search can start with the new data.
- next_search_start_ = end - begin;
- }
-
- // Check if buffer is full.
- if (streambuf_.size() == streambuf_.max_size())
- {
- std::size_t bytes = 0;
- boost::system::error_code ec2(error::not_found);
- handler_(ec2, bytes);
- return;
- }
-
- // Start a new asynchronous read operation to obtain more data.
- std::size_t bytes_available =
- std::min<std::size_t>(512, streambuf_.max_size() - streambuf_.size());
- stream_.async_read_some(streambuf_.prepare(bytes_available), *this);
- }
-
- //private:
- AsyncReadStream& stream_;
- boost::asio::basic_streambuf<Allocator>& streambuf_;
- std::string delim_;
- std::size_t next_search_start_;
- ReadHandler handler_;
- };
-
- template <typename AsyncReadStream, typename Allocator, typename ReadHandler>
- inline void* asio_handler_allocate(std::size_t size,
- read_until_delim_string_handler<AsyncReadStream,
- Allocator, ReadHandler>* this_handler)
- {
- return boost_asio_handler_alloc_helpers::allocate(
- size, this_handler->handler_);
- }
-
- template <typename AsyncReadStream, typename Allocator, typename ReadHandler>
- inline void asio_handler_deallocate(void* pointer, std::size_t size,
- read_until_delim_string_handler<AsyncReadStream,
- Allocator, ReadHandler>* this_handler)
- {
- boost_asio_handler_alloc_helpers::deallocate(
- pointer, size, this_handler->handler_);
- }
-
- template <typename Function, typename AsyncReadStream,
- typename Allocator, typename ReadHandler>
- inline void asio_handler_invoke(const Function& function,
- read_until_delim_string_handler<AsyncReadStream,
- Allocator, ReadHandler>* this_handler)
- {
- boost_asio_handler_invoke_helpers::invoke(
- function, this_handler->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)
-{
- // Determine the range of the data to be searched.
- typedef typename boost::asio::basic_streambuf<
- Allocator>::const_buffers_type const_buffers_type;
- typedef boost::asio::buffers_iterator<const_buffers_type> iterator;
- const_buffers_type buffers = b.data();
- iterator begin = iterator::begin(buffers);
- iterator end = iterator::end(buffers);
-
- // Look for a match.
- std::size_t next_search_start;
- std::pair<iterator, bool> result = boost::asio::detail::partial_search(
- begin, end, delim.begin(), delim.end());
- if (result.first != end)
- {
- if (result.second)
- {
- // Full match. We're done.
- boost::system::error_code ec;
- std::size_t bytes = result.first - begin + delim.length();
- s.get_io_service().post(detail::bind_handler(handler, ec, bytes));
- return;
- }
- else
- {
- // Partial match. Next search needs to start from beginning of match.
- next_search_start = result.first - begin;
- }
- }
- else
- {
- // No match. Next search can start with the new data.
- next_search_start = end - begin;
- }
-
- // Check if buffer is full.
- if (b.size() == b.max_size())
- {
- boost::system::error_code ec(error::not_found);
- s.get_io_service().post(detail::bind_handler(handler, ec, 0));
- return;
- }
-
- // Start a new asynchronous read operation to obtain more data.
- std::size_t bytes_available =
- std::min<std::size_t>(512, b.max_size() - b.size());
- s.async_read_some(b.prepare(bytes_available),
- detail::read_until_delim_string_handler<
- AsyncReadStream, Allocator, ReadHandler>(
- s, b, delim, next_search_start, handler));
-}
-
-namespace detail
-{
- template <typename AsyncReadStream, typename Allocator, typename ReadHandler>
- class read_until_expr_handler
- {
- public:
- read_until_expr_handler(AsyncReadStream& stream,
- boost::asio::basic_streambuf<Allocator>& streambuf,
- const boost::regex& expr, std::size_t next_search_start,
- ReadHandler handler)
- : stream_(stream),
- streambuf_(streambuf),
- expr_(expr),
- next_search_start_(next_search_start),
- handler_(handler)
- {
- }
-
- void operator()(const boost::system::error_code& ec,
- std::size_t bytes_transferred)
- {
- // Check for errors.
- if (ec)
- {
- std::size_t bytes = 0;
- handler_(ec, bytes);
- return;
- }
-
- // Commit received data to streambuf's get area.
- streambuf_.commit(bytes_transferred);
-
- // Determine the range of the data to be searched.
- typedef typename boost::asio::basic_streambuf<
- Allocator>::const_buffers_type const_buffers_type;
- typedef boost::asio::buffers_iterator<const_buffers_type> iterator;
- const_buffers_type buffers = streambuf_.data();
- iterator begin = iterator::begin(buffers);
- iterator start = begin + next_search_start_;
- iterator end = iterator::end(buffers);
-
- // Look for a match.
- boost::match_results<iterator> match_results;
- if (boost::regex_search(start, end, match_results, expr_,
- boost::match_default | boost::match_partial))
- {
- if (match_results[0].matched)
- {
- // Full match. We're done.
- std::size_t bytes = match_results[0].second - begin;
- handler_(ec, bytes);
- return;
- }
- else
- {
- // Partial match. Next search needs to start from beginning of match.
- next_search_start_ = match_results[0].first - begin;
- }
- }
- else
- {
- // No match. Next search can start with the new data.
- next_search_start_ = end - begin;
- }
-
- // Check if buffer is full.
- if (streambuf_.size() == streambuf_.max_size())
- {
- std::size_t bytes = 0;
- boost::system::error_code ec(error::not_found);
- handler_(ec, bytes);
- return;
- }
-
- // Start a new asynchronous read operation to obtain more data.
- std::size_t bytes_available =
- std::min<std::size_t>(512, streambuf_.max_size() - streambuf_.size());
- stream_.async_read_some(streambuf_.prepare(bytes_available), *this);
- }
-
- //private:
- AsyncReadStream& stream_;
- boost::asio::basic_streambuf<Allocator>& streambuf_;
- boost::regex expr_;
- std::size_t next_search_start_;
- ReadHandler handler_;
- };
-
- template <typename AsyncReadStream, typename Allocator, typename ReadHandler>
- inline void* asio_handler_allocate(std::size_t size,
- read_until_expr_handler<AsyncReadStream,
- Allocator, ReadHandler>* this_handler)
- {
- return boost_asio_handler_alloc_helpers::allocate(
- size, this_handler->handler_);
- }
-
- template <typename AsyncReadStream, typename Allocator, typename ReadHandler>
- inline void asio_handler_deallocate(void* pointer, std::size_t size,
- read_until_expr_handler<AsyncReadStream,
- Allocator, ReadHandler>* this_handler)
- {
- boost_asio_handler_alloc_helpers::deallocate(
- pointer, size, this_handler->handler_);
- }
-
- template <typename Function, typename AsyncReadStream, typename Allocator,
- typename ReadHandler>
- inline void asio_handler_invoke(const Function& function,
- read_until_expr_handler<AsyncReadStream,
- Allocator, ReadHandler>* this_handler)
- {
- boost_asio_handler_invoke_helpers::invoke(
- function, this_handler->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)
-{
- // Determine the range of the data to be searched.
- typedef typename boost::asio::basic_streambuf<
- Allocator>::const_buffers_type const_buffers_type;
- typedef boost::asio::buffers_iterator<const_buffers_type> iterator;
- const_buffers_type buffers = b.data();
- iterator begin = iterator::begin(buffers);
- iterator end = iterator::end(buffers);
-
- // Look for a match.
- std::size_t next_search_start;
- boost::match_results<iterator> match_results;
- if (boost::regex_search(begin, end, match_results, expr,
- boost::match_default | boost::match_partial))
- {
- if (match_results[0].matched)
- {
- // Full match. We're done.
- boost::system::error_code ec;
- std::size_t bytes = match_results[0].second - begin;
- s.get_io_service().post(detail::bind_handler(handler, ec, bytes));
- return;
- }
- else
- {
- // Partial match. Next search needs to start from beginning of match.
- next_search_start = match_results[0].first - begin;
- }
- }
- else
- {
- // No match. Next search can start with the new data.
- next_search_start = end - begin;
- }
-
- // Check if buffer is full.
- if (b.size() == b.max_size())
- {
- boost::system::error_code ec(error::not_found);
- s.get_io_service().post(detail::bind_handler(handler, ec, 0));
- return;
- }
-
- // Start a new asynchronous read operation to obtain more data.
- std::size_t bytes_available =
- std::min<std::size_t>(512, b.max_size() - b.size());
- s.async_read_some(b.prepare(bytes_available),
- detail::read_until_expr_handler<AsyncReadStream, Allocator, ReadHandler>(
- s, b, expr, next_search_start, handler));
-}
-
-namespace detail
-{
- template <typename AsyncReadStream, typename Allocator,
- typename MatchCondition, typename ReadHandler>
- class read_until_match_handler
- {
- public:
- read_until_match_handler(AsyncReadStream& stream,
- boost::asio::basic_streambuf<Allocator>& streambuf,
- MatchCondition match_condition, std::size_t next_search_start,
- ReadHandler handler)
- : stream_(stream),
- streambuf_(streambuf),
- match_condition_(match_condition),
- next_search_start_(next_search_start),
- handler_(handler)
- {
- }
-
- void operator()(const boost::system::error_code& ec,
- std::size_t bytes_transferred)
- {
- // Check for errors.
- if (ec)
- {
- std::size_t bytes = 0;
- handler_(ec, bytes);
- return;
- }
-
- // Commit received data to streambuf's get area.
- streambuf_.commit(bytes_transferred);
-
- // Determine the range of the data to be searched.
- typedef typename boost::asio::basic_streambuf<
- Allocator>::const_buffers_type const_buffers_type;
- typedef boost::asio::buffers_iterator<const_buffers_type> iterator;
- const_buffers_type buffers = streambuf_.data();
- iterator begin = iterator::begin(buffers);
- iterator start = begin + next_search_start_;
- iterator end = iterator::end(buffers);
-
- // Look for a match.
- std::pair<iterator, bool> result = match_condition_(start, end);
- if (result.second)
- {
- // Full match. We're done.
- std::size_t bytes = result.first - begin;
- handler_(ec, bytes);
- return;
- }
- else if (result.first != end)
- {
- // Partial match. Next search needs to start from beginning of match.
- next_search_start_ = result.first - begin;
- }
- else
- {
- // No match. Next search can start with the new data.
- next_search_start_ = end - begin;
- }
-
- // Check if buffer is full.
- if (streambuf_.size() == streambuf_.max_size())
- {
- std::size_t bytes = 0;
- boost::system::error_code ec(error::not_found);
- handler_(ec, bytes);
- return;
- }
-
- // Start a new asynchronous read operation to obtain more data.
- std::size_t bytes_available =
- std::min<std::size_t>(512, streambuf_.max_size() - streambuf_.size());
- stream_.async_read_some(streambuf_.prepare(bytes_available), *this);
- }
-
- //private:
- AsyncReadStream& stream_;
- boost::asio::basic_streambuf<Allocator>& streambuf_;
- MatchCondition match_condition_;
- std::size_t next_search_start_;
- ReadHandler handler_;
- };
-
- template <typename AsyncReadStream, typename Allocator,
- typename MatchCondition, typename ReadHandler>
- inline void* asio_handler_allocate(std::size_t size,
- read_until_match_handler<AsyncReadStream,
- Allocator, MatchCondition, ReadHandler>* this_handler)
- {
- return boost_asio_handler_alloc_helpers::allocate(
- size, this_handler->handler_);
- }
-
- template <typename AsyncReadStream, typename Allocator,
- typename MatchCondition, typename ReadHandler>
- inline void asio_handler_deallocate(void* pointer, std::size_t size,
- read_until_match_handler<AsyncReadStream,
- Allocator, MatchCondition, ReadHandler>* this_handler)
- {
- boost_asio_handler_alloc_helpers::deallocate(
- pointer, size, 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_handler<AsyncReadStream,
- Allocator, MatchCondition, ReadHandler>* this_handler)
- {
- boost_asio_handler_invoke_helpers::invoke(
- function, this_handler->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,
- typename boost::enable_if<is_match_condition<MatchCondition> >::type*)
-{
- // Determine the range of the data to be searched.
- typedef typename boost::asio::basic_streambuf<
- Allocator>::const_buffers_type const_buffers_type;
- typedef boost::asio::buffers_iterator<const_buffers_type> iterator;
- const_buffers_type buffers = b.data();
- iterator begin = iterator::begin(buffers);
- iterator end = iterator::end(buffers);
-
- // Look for a match.
- std::size_t next_search_start;
- std::pair<iterator, bool> result = match_condition(begin, end);
- if (result.second)
- {
- // Full match. We're done.
- boost::system::error_code ec;
- std::size_t bytes = result.first - begin;
- s.get_io_service().post(detail::bind_handler(handler, ec, bytes));
- return;
- }
- else if (result.first != end)
- {
- // Partial match. Next search needs to start from beginning of match.
- next_search_start = result.first - begin;
- }
- else
- {
- // No match. Next search can start with the new data.
- next_search_start = end - begin;
- }
-
- // Check if buffer is full.
- if (b.size() == b.max_size())
- {
- boost::system::error_code ec(error::not_found);
- s.get_io_service().post(detail::bind_handler(handler, ec, 0));
- return;
- }
-
- // Start a new asynchronous read operation to obtain more data.
- std::size_t bytes_available =
- std::min<std::size_t>(512, b.max_size() - b.size());
- s.async_read_some(b.prepare(bytes_available),
- detail::read_until_match_handler<
- AsyncReadStream, Allocator, MatchCondition, ReadHandler>(
- s, b, match_condition, next_search_start, handler));
-}
-
-} // namespace asio
-} // namespace boost
-
-#include <boost/asio/detail/pop_options.hpp>
-
-#endif // BOOST_ASIO_READ_UNTIL_IPP
diff --git a/3rdParty/Boost/src/boost/asio/impl/serial_port_base.hpp b/3rdParty/Boost/src/boost/asio/impl/serial_port_base.hpp
new file mode 100644
index 0000000..2b291f3
--- /dev/null
+++ b/3rdParty/Boost/src/boost/asio/impl/serial_port_base.hpp
@@ -0,0 +1,61 @@
+//
+// impl/serial_port_base.hpp
+// ~~~~~~~~~~~~~~~~~~~~~~~~~
+//
+// Copyright (c) 2003-2010 Christopher M. Kohlhoff (chris at kohlhoff dot com)
+// Copyright (c) 2008 Rep Invariant Systems, Inc. (info@repinvariant.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)
+//
+
+#ifndef BOOST_ASIO_IMPL_SERIAL_PORT_BASE_HPP
+#define BOOST_ASIO_IMPL_SERIAL_PORT_BASE_HPP
+
+#if defined(_MSC_VER) && (_MSC_VER >= 1200)
+# pragma once
+#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
+
+#include <boost/asio/detail/push_options.hpp>
+
+namespace boost {
+namespace asio {
+
+inline serial_port_base::baud_rate::baud_rate(unsigned int rate)
+ : value_(rate)
+{
+}
+
+inline unsigned int serial_port_base::baud_rate::value() const
+{
+ return value_;
+}
+
+inline serial_port_base::flow_control::type
+serial_port_base::flow_control::value() const
+{
+ return value_;
+}
+
+inline serial_port_base::parity::type serial_port_base::parity::value() const
+{
+ return value_;
+}
+
+inline serial_port_base::stop_bits::type
+serial_port_base::stop_bits::value() const
+{
+ return value_;
+}
+
+inline unsigned int serial_port_base::character_size::value() const
+{
+ return value_;
+}
+
+} // namespace asio
+} // namespace boost
+
+#include <boost/asio/detail/pop_options.hpp>
+
+#endif // BOOST_ASIO_IMPL_SERIAL_PORT_BASE_HPP
diff --git a/3rdParty/Boost/src/boost/asio/impl/serial_port_base.ipp b/3rdParty/Boost/src/boost/asio/impl/serial_port_base.ipp
index 2775a02..2bfe58a 100644
--- a/3rdParty/Boost/src/boost/asio/impl/serial_port_base.ipp
+++ b/3rdParty/Boost/src/boost/asio/impl/serial_port_base.ipp
@@ -1,6 +1,6 @@
//
-// serial_port_base.ipp
-// ~~~~~~~~~~~~~~~~~~~~
+// impl/serial_port_base.ipp
+// ~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2010 Christopher M. Kohlhoff (chris at kohlhoff dot com)
// Copyright (c) 2008 Rep Invariant Systems, Inc. (info@repinvariant.com)
@@ -9,33 +9,36 @@
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
-#ifndef BOOST_ASIO_SERIAL_PORT_BASE_IPP
-#define BOOST_ASIO_SERIAL_PORT_BASE_IPP
+#ifndef BOOST_ASIO_IMPL_SERIAL_PORT_BASE_IPP
+#define BOOST_ASIO_IMPL_SERIAL_PORT_BASE_IPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
-#include <boost/asio/detail/push_options.hpp>
+#include <boost/asio/detail/config.hpp>
-#include <boost/asio/detail/push_options.hpp>
+#if defined(BOOST_ASIO_HAS_SERIAL_PORT)
+
+#include <stdexcept>
#include <boost/throw_exception.hpp>
-#include <boost/asio/detail/pop_options.hpp>
+#include <boost/asio/error.hpp>
+#include <boost/asio/serial_port_base.hpp>
-namespace boost {
-namespace asio {
+#if defined(GENERATING_DOCUMENTATION)
+# define BOOST_ASIO_OPTION_STORAGE implementation_defined
+#elif defined(BOOST_WINDOWS) || defined(__CYGWIN__)
+# define BOOST_ASIO_OPTION_STORAGE DCB
+#else
+# define BOOST_ASIO_OPTION_STORAGE termios
+#endif
-inline serial_port_base::baud_rate::baud_rate(unsigned int rate)
- : value_(rate)
-{
-}
+#include <boost/asio/detail/push_options.hpp>
-inline unsigned int serial_port_base::baud_rate::value() const
-{
- return value_;
-}
+namespace boost {
+namespace asio {
-inline boost::system::error_code serial_port_base::baud_rate::store(
+boost::system::error_code serial_port_base::baud_rate::store(
BOOST_ASIO_OPTION_STORAGE& storage, boost::system::error_code& ec) const
{
#if defined(BOOST_WINDOWS) || defined(__CYGWIN__)
@@ -123,7 +126,7 @@ inline boost::system::error_code serial_port_base::baud_rate::store(
return ec;
}
-inline boost::system::error_code serial_port_base::baud_rate::load(
+boost::system::error_code serial_port_base::baud_rate::load(
const BOOST_ASIO_OPTION_STORAGE& storage, boost::system::error_code& ec)
{
#if defined(BOOST_WINDOWS) || defined(__CYGWIN__)
@@ -205,7 +208,7 @@ inline boost::system::error_code serial_port_base::baud_rate::load(
return ec;
}
-inline serial_port_base::flow_control::flow_control(
+serial_port_base::flow_control::flow_control(
serial_port_base::flow_control::type t)
: value_(t)
{
@@ -216,13 +219,7 @@ inline serial_port_base::flow_control::flow_control(
}
}
-inline serial_port_base::flow_control::type
-serial_port_base::flow_control::value() const
-{
- return value_;
-}
-
-inline boost::system::error_code serial_port_base::flow_control::store(
+boost::system::error_code serial_port_base::flow_control::store(
BOOST_ASIO_OPTION_STORAGE& storage, boost::system::error_code& ec) const
{
#if defined(BOOST_WINDOWS) || defined(__CYGWIN__)
@@ -256,12 +253,16 @@ inline boost::system::error_code serial_port_base::flow_control::store(
storage.c_iflag &= ~(IXOFF | IXON);
# if defined(_BSD_SOURCE)
storage.c_cflag &= ~CRTSCTS;
+# elif defined(__QNXNTO__)
+ storage.c_cflag &= ~(IHFLOW | OHFLOW);
# endif
break;
case software:
storage.c_iflag |= IXOFF | IXON;
# if defined(_BSD_SOURCE)
storage.c_cflag &= ~CRTSCTS;
+# elif defined(__QNXNTO__)
+ storage.c_cflag &= ~(IHFLOW | OHFLOW);
# endif
break;
case hardware:
@@ -269,6 +270,10 @@ inline boost::system::error_code serial_port_base::flow_control::store(
storage.c_iflag &= ~(IXOFF | IXON);
storage.c_cflag |= CRTSCTS;
break;
+# elif defined(__QNXNTO__)
+ storage.c_iflag &= ~(IXOFF | IXON);
+ storage.c_cflag |= (IHFLOW | OHFLOW);
+ break;
# else
ec = boost::asio::error::operation_not_supported;
return ec;
@@ -281,7 +286,7 @@ inline boost::system::error_code serial_port_base::flow_control::store(
return ec;
}
-inline boost::system::error_code serial_port_base::flow_control::load(
+boost::system::error_code serial_port_base::flow_control::load(
const BOOST_ASIO_OPTION_STORAGE& storage, boost::system::error_code& ec)
{
#if defined(BOOST_WINDOWS) || defined(__CYGWIN__)
@@ -307,6 +312,11 @@ inline boost::system::error_code serial_port_base::flow_control::load(
{
value_ = hardware;
}
+# elif defined(__QNXNTO__)
+ else if (storage.c_cflag & IHFLOW && storage.c_cflag & OHFLOW)
+ {
+ value_ = hardware;
+ }
# endif
else
{
@@ -317,7 +327,7 @@ inline boost::system::error_code serial_port_base::flow_control::load(
return ec;
}
-inline serial_port_base::parity::parity(serial_port_base::parity::type t)
+serial_port_base::parity::parity(serial_port_base::parity::type t)
: value_(t)
{
if (t != none && t != odd && t != even)
@@ -327,12 +337,7 @@ inline serial_port_base::parity::parity(serial_port_base::parity::type t)
}
}
-inline serial_port_base::parity::type serial_port_base::parity::value() const
-{
- return value_;
-}
-
-inline boost::system::error_code serial_port_base::parity::store(
+boost::system::error_code serial_port_base::parity::store(
BOOST_ASIO_OPTION_STORAGE& storage, boost::system::error_code& ec) const
{
#if defined(BOOST_WINDOWS) || defined(__CYGWIN__)
@@ -379,7 +384,7 @@ inline boost::system::error_code serial_port_base::parity::store(
return ec;
}
-inline boost::system::error_code serial_port_base::parity::load(
+boost::system::error_code serial_port_base::parity::load(
const BOOST_ASIO_OPTION_STORAGE& storage, boost::system::error_code& ec)
{
#if defined(BOOST_WINDOWS) || defined(__CYGWIN__)
@@ -416,7 +421,7 @@ inline boost::system::error_code serial_port_base::parity::load(
return ec;
}
-inline serial_port_base::stop_bits::stop_bits(
+serial_port_base::stop_bits::stop_bits(
serial_port_base::stop_bits::type t)
: value_(t)
{
@@ -427,13 +432,7 @@ inline serial_port_base::stop_bits::stop_bits(
}
}
-inline serial_port_base::stop_bits::type
-serial_port_base::stop_bits::value() const
-{
- return value_;
-}
-
-inline boost::system::error_code serial_port_base::stop_bits::store(
+boost::system::error_code serial_port_base::stop_bits::store(
BOOST_ASIO_OPTION_STORAGE& storage, boost::system::error_code& ec) const
{
#if defined(BOOST_WINDOWS) || defined(__CYGWIN__)
@@ -469,7 +468,7 @@ inline boost::system::error_code serial_port_base::stop_bits::store(
return ec;
}
-inline boost::system::error_code serial_port_base::stop_bits::load(
+boost::system::error_code serial_port_base::stop_bits::load(
const BOOST_ASIO_OPTION_STORAGE& storage, boost::system::error_code& ec)
{
#if defined(BOOST_WINDOWS) || defined(__CYGWIN__)
@@ -496,7 +495,7 @@ inline boost::system::error_code serial_port_base::stop_bits::load(
return ec;
}
-inline serial_port_base::character_size::character_size(unsigned int t)
+serial_port_base::character_size::character_size(unsigned int t)
: value_(t)
{
if (t < 5 || t > 8)
@@ -506,12 +505,7 @@ inline serial_port_base::character_size::character_size(unsigned int t)
}
}
-inline unsigned int serial_port_base::character_size::value() const
-{
- return value_;
-}
-
-inline boost::system::error_code serial_port_base::character_size::store(
+boost::system::error_code serial_port_base::character_size::store(
BOOST_ASIO_OPTION_STORAGE& storage, boost::system::error_code& ec) const
{
#if defined(BOOST_WINDOWS) || defined(__CYGWIN__)
@@ -531,7 +525,7 @@ inline boost::system::error_code serial_port_base::character_size::store(
return ec;
}
-inline boost::system::error_code serial_port_base::character_size::load(
+boost::system::error_code serial_port_base::character_size::load(
const BOOST_ASIO_OPTION_STORAGE& storage, boost::system::error_code& ec)
{
#if defined(BOOST_WINDOWS) || defined(__CYGWIN__)
@@ -556,4 +550,8 @@ inline boost::system::error_code serial_port_base::character_size::load(
#include <boost/asio/detail/pop_options.hpp>
-#endif // BOOST_ASIO_SERIAL_PORT_BASE_IPP
+#undef BOOST_ASIO_OPTION_STORAGE
+
+#endif // defined(BOOST_ASIO_HAS_SERIAL_PORT)
+
+#endif // BOOST_ASIO_IMPL_SERIAL_PORT_BASE_IPP
diff --git a/3rdParty/Boost/src/boost/asio/impl/write.ipp b/3rdParty/Boost/src/boost/asio/impl/write.hpp
index 28a5273..fa2982a 100644
--- a/3rdParty/Boost/src/boost/asio/impl/write.ipp
+++ b/3rdParty/Boost/src/boost/asio/impl/write.hpp
@@ -1,6 +1,6 @@
//
-// write.ipp
-// ~~~~~~~~~
+// impl/write.hpp
+// ~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2010 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
@@ -8,15 +8,13 @@
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
-#ifndef BOOST_ASIO_WRITE_IPP
-#define BOOST_ASIO_WRITE_IPP
+#ifndef BOOST_ASIO_IMPL_WRITE_HPP
+#define BOOST_ASIO_IMPL_WRITE_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
-#include <boost/asio/detail/push_options.hpp>
-
#include <boost/asio/buffer.hpp>
#include <boost/asio/completion_condition.hpp>
#include <boost/asio/detail/base_from_completion_cond.hpp>
@@ -26,6 +24,8 @@
#include <boost/asio/detail/handler_invoke_helpers.hpp>
#include <boost/asio/detail/throw_error.hpp>
+#include <boost/asio/detail/push_options.hpp>
+
namespace boost {
namespace asio {
@@ -123,31 +123,30 @@ namespace detail
stream_(stream),
buffers_(buffers),
total_transferred_(0),
- handler_(handler),
- start_(true)
+ handler_(handler)
{
}
void operator()(const boost::system::error_code& ec,
- std::size_t bytes_transferred)
+ std::size_t bytes_transferred, int start = 0)
{
- switch (start_)
+ switch (start)
{
- case true: start_ = false;
- buffers_.prepare(this->check(ec, total_transferred_));
+ case 1:
+ buffers_.prepare(this->check_for_completion(ec, total_transferred_));
for (;;)
{
stream_.async_write_some(buffers_, *this);
return; default:
total_transferred_ += bytes_transferred;
buffers_.consume(bytes_transferred);
- buffers_.prepare(this->check(ec, total_transferred_));
+ buffers_.prepare(this->check_for_completion(ec, total_transferred_));
if ((!ec && bytes_transferred == 0)
|| buffers_.begin() == buffers_.end())
break;
}
- handler_(ec, total_transferred_);
+ handler_(ec, static_cast<const std::size_t&>(total_transferred_));
}
}
@@ -157,7 +156,6 @@ namespace detail
const_buffer, ConstBufferSequence> buffers_;
std::size_t total_transferred_;
WriteHandler handler_;
- bool start_;
};
template <typename AsyncWriteStream,
@@ -176,19 +174,18 @@ namespace detail
stream_(stream),
buffer_(buffers),
total_transferred_(0),
- handler_(handler),
- start_(true)
+ handler_(handler)
{
}
void operator()(const boost::system::error_code& ec,
- std::size_t bytes_transferred)
+ std::size_t bytes_transferred, int start = 0)
{
std::size_t n = 0;
- switch (start_)
+ switch (start)
{
- case true: start_ = false;
- n = this->check(ec, total_transferred_);
+ case 1:
+ n = this->check_for_completion(ec, total_transferred_);
for (;;)
{
stream_.async_write_some(boost::asio::buffer(
@@ -196,12 +193,12 @@ namespace detail
return; default:
total_transferred_ += bytes_transferred;
if ((!ec && bytes_transferred == 0)
- || (n = this->check(ec, total_transferred_)) == 0
+ || (n = this->check_for_completion(ec, total_transferred_)) == 0
|| total_transferred_ == boost::asio::buffer_size(buffer_))
break;
}
- handler_(ec, total_transferred_);
+ handler_(ec, static_cast<const std::size_t&>(total_transferred_));
}
}
@@ -210,7 +207,6 @@ namespace detail
boost::asio::mutable_buffer buffer_;
std::size_t total_transferred_;
WriteHandler handler_;
- bool start_;
};
template <typename AsyncWriteStream,
@@ -229,19 +225,18 @@ namespace detail
stream_(stream),
buffer_(buffers),
total_transferred_(0),
- handler_(handler),
- start_(true)
+ handler_(handler)
{
}
void operator()(const boost::system::error_code& ec,
- std::size_t bytes_transferred)
+ std::size_t bytes_transferred, int start = 0)
{
std::size_t n = 0;
- switch (start_)
+ switch (start)
{
- case true: start_ = false;
- n = this->check(ec, total_transferred_);
+ case 1:
+ n = this->check_for_completion(ec, total_transferred_);
for (;;)
{
stream_.async_write_some(boost::asio::buffer(
@@ -249,12 +244,12 @@ namespace detail
return; default:
total_transferred_ += bytes_transferred;
if ((!ec && bytes_transferred == 0)
- || (n = this->check(ec, total_transferred_)) == 0
+ || (n = this->check_for_completion(ec, total_transferred_)) == 0
|| total_transferred_ == boost::asio::buffer_size(buffer_))
break;
}
- handler_(ec, total_transferred_);
+ handler_(ec, static_cast<const std::size_t&>(total_transferred_));
}
}
@@ -263,7 +258,6 @@ namespace detail
boost::asio::const_buffer buffer_;
std::size_t total_transferred_;
WriteHandler handler_;
- bool start_;
};
template <typename AsyncWriteStream, typename ConstBufferSequence,
@@ -306,7 +300,7 @@ inline void async_write(AsyncWriteStream& s, const ConstBufferSequence& buffers,
detail::write_op<AsyncWriteStream, ConstBufferSequence,
CompletionCondition, WriteHandler>(
s, buffers, completion_condition, handler)(
- boost::system::error_code(), 0);
+ boost::system::error_code(), 0, 1);
}
template <typename AsyncWriteStream, typename ConstBufferSequence,
@@ -334,7 +328,7 @@ namespace detail
}
void operator()(const boost::system::error_code& ec,
- std::size_t bytes_transferred)
+ const std::size_t bytes_transferred)
{
streambuf_.consume(bytes_transferred);
handler_(ec, bytes_transferred);
@@ -401,4 +395,4 @@ inline void async_write(AsyncWriteStream& s,
#include <boost/asio/detail/pop_options.hpp>
-#endif // BOOST_ASIO_WRITE_IPP
+#endif // BOOST_ASIO_IMPL_WRITE_HPP
diff --git a/3rdParty/Boost/src/boost/asio/impl/write_at.ipp b/3rdParty/Boost/src/boost/asio/impl/write_at.hpp
index 3d1a112..aad64ef 100644
--- a/3rdParty/Boost/src/boost/asio/impl/write_at.ipp
+++ b/3rdParty/Boost/src/boost/asio/impl/write_at.hpp
@@ -1,6 +1,6 @@
//
-// write_at.ipp
-// ~~~~~~~~~~~~
+// impl/write_at.hpp
+// ~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2010 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
@@ -8,23 +8,24 @@
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
-#ifndef BOOST_ASIO_WRITE_AT_IPP
-#define BOOST_ASIO_WRITE_AT_IPP
+#ifndef BOOST_ASIO_IMPL_WRITE_AT_HPP
+#define BOOST_ASIO_IMPL_WRITE_AT_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
-#include <boost/asio/detail/push_options.hpp>
-
#include <boost/asio/buffer.hpp>
#include <boost/asio/completion_condition.hpp>
+#include <boost/asio/detail/base_from_completion_cond.hpp>
#include <boost/asio/detail/bind_handler.hpp>
#include <boost/asio/detail/consuming_buffers.hpp>
#include <boost/asio/detail/handler_alloc_helpers.hpp>
#include <boost/asio/detail/handler_invoke_helpers.hpp>
#include <boost/asio/detail/throw_error.hpp>
+#include <boost/asio/detail/push_options.hpp>
+
namespace boost {
namespace asio {
@@ -119,55 +120,166 @@ namespace detail
{
template <typename AsyncRandomAccessWriteDevice, typename ConstBufferSequence,
typename CompletionCondition, typename WriteHandler>
- class write_at_handler
+ class write_at_op
+ : detail::base_from_completion_cond<CompletionCondition>
{
public:
- typedef boost::asio::detail::consuming_buffers<
- const_buffer, ConstBufferSequence> buffers_type;
-
- write_at_handler(AsyncRandomAccessWriteDevice& stream,
- boost::uint64_t offset, const buffers_type& buffers,
+ write_at_op(AsyncRandomAccessWriteDevice& device,
+ boost::uint64_t offset, const ConstBufferSequence& buffers,
CompletionCondition completion_condition, WriteHandler handler)
- : stream_(stream),
+ : detail::base_from_completion_cond<
+ CompletionCondition>(completion_condition),
+ device_(device),
+ offset_(offset),
buffers_(buffers),
+ total_transferred_(0),
+ handler_(handler)
+ {
+ }
+
+ void operator()(const boost::system::error_code& ec,
+ std::size_t bytes_transferred, int start = 0)
+ {
+ switch (start)
+ {
+ case 1:
+ buffers_.prepare(this->check_for_completion(ec, total_transferred_));
+ for (;;)
+ {
+ device_.async_write_some_at(
+ offset_ + total_transferred_, buffers_, *this);
+ return; default:
+ total_transferred_ += bytes_transferred;
+ buffers_.consume(bytes_transferred);
+ buffers_.prepare(this->check_for_completion(ec, total_transferred_));
+ if ((!ec && bytes_transferred == 0)
+ || buffers_.begin() == buffers_.end())
+ break;
+ }
+
+ handler_(ec, static_cast<const std::size_t&>(total_transferred_));
+ }
+ }
+
+ //private:
+ AsyncRandomAccessWriteDevice& device_;
+ boost::uint64_t offset_;
+ boost::asio::detail::consuming_buffers<
+ const_buffer, ConstBufferSequence> buffers_;
+ std::size_t total_transferred_;
+ WriteHandler handler_;
+ };
+
+ template <typename AsyncRandomAccessWriteDevice,
+ typename CompletionCondition, typename WriteHandler>
+ class write_at_op<AsyncRandomAccessWriteDevice,
+ boost::asio::mutable_buffers_1, CompletionCondition, WriteHandler>
+ : detail::base_from_completion_cond<CompletionCondition>
+ {
+ public:
+ write_at_op(AsyncRandomAccessWriteDevice& device,
+ boost::uint64_t offset, const boost::asio::mutable_buffers_1& buffers,
+ CompletionCondition completion_condition,
+ WriteHandler handler)
+ : detail::base_from_completion_cond<
+ CompletionCondition>(completion_condition),
+ device_(device),
offset_(offset),
+ buffer_(buffers),
total_transferred_(0),
- completion_condition_(completion_condition),
handler_(handler)
{
}
void operator()(const boost::system::error_code& ec,
- std::size_t bytes_transferred)
+ std::size_t bytes_transferred, int start = 0)
{
- total_transferred_ += bytes_transferred;
- buffers_.consume(bytes_transferred);
- buffers_.prepare(detail::adapt_completion_condition_result(
- completion_condition_(ec, total_transferred_)));
- if (buffers_.begin() == buffers_.end())
+ std::size_t n = 0;
+ switch (start)
{
- handler_(ec, total_transferred_);
+ case 1:
+ n = this->check_for_completion(ec, total_transferred_);
+ for (;;)
+ {
+ device_.async_write_some_at(offset_ + total_transferred_,
+ boost::asio::buffer(buffer_ + total_transferred_, n), *this);
+ return; default:
+ total_transferred_ += bytes_transferred;
+ if ((!ec && bytes_transferred == 0)
+ || (n = this->check_for_completion(ec, total_transferred_)) == 0
+ || total_transferred_ == boost::asio::buffer_size(buffer_))
+ break;
+ }
+
+ handler_(ec, static_cast<const std::size_t&>(total_transferred_));
}
- else
+ }
+
+ //private:
+ AsyncRandomAccessWriteDevice& device_;
+ boost::uint64_t offset_;
+ boost::asio::mutable_buffer buffer_;
+ std::size_t total_transferred_;
+ WriteHandler handler_;
+ };
+
+ template <typename AsyncRandomAccessWriteDevice,
+ typename CompletionCondition, typename WriteHandler>
+ class write_at_op<AsyncRandomAccessWriteDevice, boost::asio::const_buffers_1,
+ CompletionCondition, WriteHandler>
+ : detail::base_from_completion_cond<CompletionCondition>
+ {
+ public:
+ write_at_op(AsyncRandomAccessWriteDevice& device,
+ boost::uint64_t offset, const boost::asio::const_buffers_1& buffers,
+ CompletionCondition completion_condition,
+ WriteHandler handler)
+ : detail::base_from_completion_cond<
+ CompletionCondition>(completion_condition),
+ device_(device),
+ offset_(offset),
+ buffer_(buffers),
+ total_transferred_(0),
+ handler_(handler)
+ {
+ }
+
+ void operator()(const boost::system::error_code& ec,
+ std::size_t bytes_transferred, int start = 0)
+ {
+ std::size_t n = 0;
+ switch (start)
{
- stream_.async_write_some_at(
- offset_ + total_transferred_, buffers_, *this);
+ case 1:
+ n = this->check_for_completion(ec, total_transferred_);
+ for (;;)
+ {
+ device_.async_write_some_at(offset_ + total_transferred_,
+ boost::asio::buffer(buffer_ + total_transferred_, n), *this);
+ return; default:
+ total_transferred_ += bytes_transferred;
+ if ((!ec && bytes_transferred == 0)
+ || (n = this->check_for_completion(ec, total_transferred_)) == 0
+ || total_transferred_ == boost::asio::buffer_size(buffer_))
+ break;
+ }
+
+ handler_(ec, static_cast<const std::size_t&>(total_transferred_));
}
}
//private:
- AsyncRandomAccessWriteDevice& stream_;
- buffers_type buffers_;
+ AsyncRandomAccessWriteDevice& device_;
boost::uint64_t offset_;
+ boost::asio::const_buffer buffer_;
std::size_t total_transferred_;
- CompletionCondition completion_condition_;
WriteHandler handler_;
};
template <typename AsyncRandomAccessWriteDevice, typename ConstBufferSequence,
typename CompletionCondition, typename WriteHandler>
inline void* asio_handler_allocate(std::size_t size,
- write_at_handler<AsyncRandomAccessWriteDevice, ConstBufferSequence,
+ write_at_op<AsyncRandomAccessWriteDevice, ConstBufferSequence,
CompletionCondition, WriteHandler>* this_handler)
{
return boost_asio_handler_alloc_helpers::allocate(
@@ -177,7 +289,7 @@ namespace detail
template <typename AsyncRandomAccessWriteDevice, typename ConstBufferSequence,
typename CompletionCondition, typename WriteHandler>
inline void asio_handler_deallocate(void* pointer, std::size_t size,
- write_at_handler<AsyncRandomAccessWriteDevice, ConstBufferSequence,
+ write_at_op<AsyncRandomAccessWriteDevice, ConstBufferSequence,
CompletionCondition, WriteHandler>* this_handler)
{
boost_asio_handler_alloc_helpers::deallocate(
@@ -188,7 +300,7 @@ namespace detail
typename ConstBufferSequence, typename CompletionCondition,
typename WriteHandler>
inline void asio_handler_invoke(const Function& function,
- write_at_handler<AsyncRandomAccessWriteDevice, ConstBufferSequence,
+ write_at_op<AsyncRandomAccessWriteDevice, ConstBufferSequence,
CompletionCondition, WriteHandler>* this_handler)
{
boost_asio_handler_invoke_helpers::invoke(
@@ -202,24 +314,10 @@ inline void async_write_at(AsyncRandomAccessWriteDevice& d,
boost::uint64_t offset, const ConstBufferSequence& buffers,
CompletionCondition completion_condition, WriteHandler handler)
{
- boost::asio::detail::consuming_buffers<
- const_buffer, ConstBufferSequence> tmp(buffers);
-
- boost::system::error_code ec;
- std::size_t total_transferred = 0;
- tmp.prepare(detail::adapt_completion_condition_result(
- completion_condition(ec, total_transferred)));
- if (tmp.begin() == tmp.end())
- {
- d.get_io_service().post(detail::bind_handler(
- handler, ec, total_transferred));
- return;
- }
-
- d.async_write_some_at(offset, tmp,
- detail::write_at_handler<AsyncRandomAccessWriteDevice,
- ConstBufferSequence, CompletionCondition, WriteHandler>(
- d, offset, tmp, completion_condition, handler));
+ detail::write_at_op<AsyncRandomAccessWriteDevice,
+ ConstBufferSequence, CompletionCondition, WriteHandler>(
+ d, offset, buffers, completion_condition, handler)(
+ boost::system::error_code(), 0, 1);
}
template <typename AsyncRandomAccessWriteDevice, typename ConstBufferSequence,
@@ -235,12 +333,12 @@ inline void async_write_at(AsyncRandomAccessWriteDevice& d,
namespace detail
{
- template <typename AsyncRandomAccessWriteDevice, typename Allocator,
- typename WriteHandler>
- class write_at_streambuf_handler
+ template <typename AsyncRandomAccessWriteDevice,
+ typename Allocator, typename WriteHandler>
+ class write_at_streambuf_op
{
public:
- write_at_streambuf_handler(
+ write_at_streambuf_op(
boost::asio::basic_streambuf<Allocator>& streambuf,
WriteHandler handler)
: streambuf_(streambuf),
@@ -249,7 +347,7 @@ namespace detail
}
void operator()(const boost::system::error_code& ec,
- std::size_t bytes_transferred)
+ const std::size_t bytes_transferred)
{
streambuf_.consume(bytes_transferred);
handler_(ec, bytes_transferred);
@@ -263,7 +361,7 @@ namespace detail
template <typename AsyncRandomAccessWriteDevice, typename Allocator,
typename WriteHandler>
inline void* asio_handler_allocate(std::size_t size,
- write_at_streambuf_handler<AsyncRandomAccessWriteDevice,
+ write_at_streambuf_op<AsyncRandomAccessWriteDevice,
Allocator, WriteHandler>* this_handler)
{
return boost_asio_handler_alloc_helpers::allocate(
@@ -273,7 +371,7 @@ namespace detail
template <typename AsyncRandomAccessWriteDevice, typename Allocator,
typename WriteHandler>
inline void asio_handler_deallocate(void* pointer, std::size_t size,
- write_at_streambuf_handler<AsyncRandomAccessWriteDevice,
+ write_at_streambuf_op<AsyncRandomAccessWriteDevice,
Allocator, WriteHandler>* this_handler)
{
boost_asio_handler_alloc_helpers::deallocate(
@@ -283,7 +381,7 @@ namespace detail
template <typename Function, typename AsyncRandomAccessWriteDevice,
typename Allocator, typename WriteHandler>
inline void asio_handler_invoke(const Function& function,
- write_at_streambuf_handler<AsyncRandomAccessWriteDevice,
+ write_at_streambuf_op<AsyncRandomAccessWriteDevice,
Allocator, WriteHandler>* this_handler)
{
boost_asio_handler_invoke_helpers::invoke(
@@ -298,7 +396,7 @@ inline void async_write_at(AsyncRandomAccessWriteDevice& d,
CompletionCondition completion_condition, WriteHandler handler)
{
async_write_at(d, offset, b.data(), completion_condition,
- detail::write_at_streambuf_handler<
+ detail::write_at_streambuf_op<
AsyncRandomAccessWriteDevice, Allocator, WriteHandler>(b, handler));
}
@@ -318,4 +416,4 @@ inline void async_write_at(AsyncRandomAccessWriteDevice& d,
#include <boost/asio/detail/pop_options.hpp>
-#endif // BOOST_ASIO_WRITE_AT_IPP
+#endif // BOOST_ASIO_IMPL_WRITE_AT_HPP