Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r85798 - in trunk: boost/asio boost/asio/impl libs/asio/test
From: chris_at_[hidden]
Date: 2013-09-20 08:00:45


Author: chris_kohlhoff
Date: 2013-09-20 08:00:44 EDT (Fri, 20 Sep 2013)
New Revision: 85798
URL: http://svn.boost.org/trac/boost/changeset/85798

Log:
Update buffered stream operations to adhere to current handler patterns.

Added:
   trunk/boost/asio/impl/buffered_read_stream.hpp (contents, props changed)
   trunk/boost/asio/impl/buffered_write_stream.hpp (contents, props changed)
Text files modified:
   trunk/boost/asio/buffered_read_stream.hpp | 191 +++-----------------
   trunk/boost/asio/buffered_stream.hpp | 32 ++-
   trunk/boost/asio/buffered_write_stream.hpp | 172 +++----------------
   trunk/boost/asio/impl/buffered_read_stream.hpp | 360 ++++++++++++++++++++++++++++++++++++++++
   trunk/boost/asio/impl/buffered_write_stream.hpp | 340 +++++++++++++++++++++++++++++++++++++
   trunk/libs/asio/test/buffered_read_stream.cpp | 109 ++++++++++++
   trunk/libs/asio/test/buffered_stream.cpp | 120 +++++++++++++
   trunk/libs/asio/test/buffered_write_stream.cpp | 109 ++++++++++++
   8 files changed, 1118 insertions(+), 315 deletions(-)

Modified: trunk/boost/asio/buffered_read_stream.hpp
==============================================================================
--- trunk/boost/asio/buffered_read_stream.hpp Thu Sep 19 17:15:15 2013 (r85797)
+++ trunk/boost/asio/buffered_read_stream.hpp 2013-09-20 08:00:44 EDT (Fri, 20 Sep 2013) (r85798)
@@ -17,6 +17,7 @@
 
 #include <boost/asio/detail/config.hpp>
 #include <cstddef>
+#include <boost/asio/async_result.hpp>
 #include <boost/asio/buffered_read_stream_fwd.hpp>
 #include <boost/asio/buffer.hpp>
 #include <boost/asio/detail/bind_handler.hpp>
@@ -134,199 +135,65 @@
   /// Start an asynchronous write. The data being written must be valid for the
   /// lifetime of the asynchronous operation.
   template <typename ConstBufferSequence, typename WriteHandler>
- void async_write_some(const ConstBufferSequence& buffers,
- WriteHandler handler)
- {
- next_layer_.async_write_some(buffers, handler);
+ BOOST_ASIO_INITFN_RESULT_TYPE(WriteHandler,
+ void (boost::system::error_code, std::size_t))
+ async_write_some(const ConstBufferSequence& buffers,
+ BOOST_ASIO_MOVE_ARG(WriteHandler) handler)
+ {
+ detail::async_result_init<
+ WriteHandler, void (boost::system::error_code, std::size_t)> init(
+ BOOST_ASIO_MOVE_CAST(WriteHandler)(handler));
+
+ next_layer_.async_write_some(buffers,
+ BOOST_ASIO_MOVE_CAST(BOOST_ASIO_HANDLER_TYPE(WriteHandler,
+ void (boost::system::error_code, std::size_t)))(init.handler));
+
+ return init.result.get();
   }
 
   /// Fill the buffer with some data. Returns the number of bytes placed in the
   /// buffer as a result of the operation. Throws an exception on failure.
- std::size_t fill()
- {
- detail::buffer_resize_guard<detail::buffered_stream_storage>
- resize_guard(storage_);
- std::size_t previous_size = storage_.size();
- storage_.resize(storage_.capacity());
- storage_.resize(previous_size + next_layer_.read_some(buffer(
- storage_.data() + previous_size,
- storage_.size() - previous_size)));
- resize_guard.commit();
- return storage_.size() - previous_size;
- }
+ std::size_t fill();
 
   /// Fill the buffer with some data. Returns the number of bytes placed in the
   /// buffer as a result of the operation, or 0 if an error occurred.
- std::size_t fill(boost::system::error_code& ec)
- {
- detail::buffer_resize_guard<detail::buffered_stream_storage>
- resize_guard(storage_);
- std::size_t previous_size = storage_.size();
- storage_.resize(storage_.capacity());
- storage_.resize(previous_size + next_layer_.read_some(buffer(
- storage_.data() + previous_size,
- storage_.size() - previous_size),
- ec));
- resize_guard.commit();
- return storage_.size() - previous_size;
- }
-
- template <typename ReadHandler>
- class fill_handler
- {
- public:
- fill_handler(boost::asio::io_service& io_service,
- detail::buffered_stream_storage& storage,
- std::size_t previous_size, ReadHandler handler)
- : io_service_(io_service),
- storage_(storage),
- previous_size_(previous_size),
- handler_(handler)
- {
- }
-
- void operator()(const boost::system::error_code& ec,
- std::size_t bytes_transferred)
- {
- storage_.resize(previous_size_ + bytes_transferred);
- io_service_.dispatch(detail::bind_handler(
- handler_, ec, bytes_transferred));
- }
-
- private:
- boost::asio::io_service& io_service_;
- detail::buffered_stream_storage& storage_;
- std::size_t previous_size_;
- ReadHandler handler_;
- };
+ std::size_t fill(boost::system::error_code& ec);
 
   /// Start an asynchronous fill.
   template <typename ReadHandler>
- void async_fill(ReadHandler handler)
- {
- std::size_t previous_size = storage_.size();
- storage_.resize(storage_.capacity());
- next_layer_.async_read_some(
- buffer(
- storage_.data() + previous_size,
- storage_.size() - previous_size),
- fill_handler<ReadHandler>(get_io_service(),
- storage_, previous_size, handler));
- }
+ BOOST_ASIO_INITFN_RESULT_TYPE(ReadHandler,
+ void (boost::system::error_code, std::size_t))
+ async_fill(BOOST_ASIO_MOVE_ARG(ReadHandler) handler);
 
   /// Read some data from the stream. Returns the number of bytes read. Throws
   /// an exception on failure.
   template <typename MutableBufferSequence>
- std::size_t read_some(const MutableBufferSequence& buffers)
- {
- if (boost::asio::buffer_size(buffers) == 0)
- return 0;
-
- if (storage_.empty())
- fill();
-
- return copy(buffers);
- }
+ std::size_t read_some(const MutableBufferSequence& buffers);
 
   /// Read some data from the stream. Returns the number of bytes read or 0 if
   /// an error occurred.
   template <typename MutableBufferSequence>
   std::size_t read_some(const MutableBufferSequence& buffers,
- boost::system::error_code& ec)
- {
- ec = boost::system::error_code();
-
- if (boost::asio::buffer_size(buffers) == 0)
- return 0;
-
- if (storage_.empty() && !fill(ec))
- return 0;
-
- return copy(buffers);
- }
-
- template <typename MutableBufferSequence, typename ReadHandler>
- class read_some_handler
- {
- public:
- read_some_handler(boost::asio::io_service& io_service,
- detail::buffered_stream_storage& storage,
- const MutableBufferSequence& buffers, ReadHandler handler)
- : io_service_(io_service),
- storage_(storage),
- buffers_(buffers),
- handler_(handler)
- {
- }
-
- void operator()(const boost::system::error_code& ec, std::size_t)
- {
- if (ec || storage_.empty())
- {
- std::size_t length = 0;
- io_service_.dispatch(detail::bind_handler(handler_, ec, length));
- }
- else
- {
- std::size_t bytes_copied = boost::asio::buffer_copy(
- buffers_, storage_.data(), storage_.size());
- storage_.consume(bytes_copied);
- io_service_.dispatch(detail::bind_handler(handler_, ec, bytes_copied));
- }
- }
-
- private:
- boost::asio::io_service& io_service_;
- detail::buffered_stream_storage& storage_;
- MutableBufferSequence buffers_;
- ReadHandler handler_;
- };
+ boost::system::error_code& ec);
 
   /// Start an asynchronous read. The buffer into which the data will be read
   /// must be valid for the lifetime of the asynchronous operation.
   template <typename MutableBufferSequence, typename ReadHandler>
- void async_read_some(const MutableBufferSequence& buffers,
- ReadHandler handler)
- {
- if (boost::asio::buffer_size(buffers) == 0)
- {
- get_io_service().post(detail::bind_handler(
- handler, boost::system::error_code(), 0));
- }
- else if (storage_.empty())
- {
- async_fill(read_some_handler<MutableBufferSequence, ReadHandler>(
- get_io_service(), storage_, buffers, handler));
- }
- else
- {
- std::size_t length = copy(buffers);
- get_io_service().post(detail::bind_handler(
- handler, boost::system::error_code(), length));
- }
- }
+ BOOST_ASIO_INITFN_RESULT_TYPE(ReadHandler,
+ void (boost::system::error_code, std::size_t))
+ async_read_some(const MutableBufferSequence& buffers,
+ BOOST_ASIO_MOVE_ARG(ReadHandler) handler);
 
   /// Peek at the incoming data on the stream. Returns the number of bytes read.
   /// Throws an exception on failure.
   template <typename MutableBufferSequence>
- std::size_t peek(const MutableBufferSequence& buffers)
- {
- if (storage_.empty())
- fill();
- return peek_copy(buffers);
- }
+ std::size_t peek(const MutableBufferSequence& buffers);
 
   /// Peek at the incoming data on the stream. Returns the number of bytes read,
   /// or 0 if an error occurred.
   template <typename MutableBufferSequence>
   std::size_t peek(const MutableBufferSequence& buffers,
- boost::system::error_code& ec)
- {
- ec = boost::system::error_code();
- if (storage_.empty() && !fill(ec))
- return 0;
- return peek_copy(buffers);
- }
+ boost::system::error_code& ec);
 
   /// Determine the amount of data that may be read without blocking.
   std::size_t in_avail()
@@ -374,4 +241,6 @@
 
 #include <boost/asio/detail/pop_options.hpp>
 
+#include <boost/asio/impl/buffered_read_stream.hpp>
+
 #endif // BOOST_ASIO_BUFFERED_READ_STREAM_HPP

Modified: trunk/boost/asio/buffered_stream.hpp
==============================================================================
--- trunk/boost/asio/buffered_stream.hpp Thu Sep 19 17:15:15 2013 (r85797)
+++ trunk/boost/asio/buffered_stream.hpp 2013-09-20 08:00:44 EDT (Fri, 20 Sep 2013) (r85798)
@@ -17,6 +17,7 @@
 
 #include <boost/asio/detail/config.hpp>
 #include <cstddef>
+#include <boost/asio/async_result.hpp>
 #include <boost/asio/buffered_read_stream.hpp>
 #include <boost/asio/buffered_write_stream.hpp>
 #include <boost/asio/buffered_stream_fwd.hpp>
@@ -123,9 +124,12 @@
 
   /// Start an asynchronous flush.
   template <typename WriteHandler>
- void async_flush(WriteHandler handler)
+ BOOST_ASIO_INITFN_RESULT_TYPE(WriteHandler,
+ void (boost::system::error_code, std::size_t))
+ async_flush(BOOST_ASIO_MOVE_ARG(WriteHandler) handler)
   {
- return stream_impl_.next_layer().async_flush(handler);
+ return stream_impl_.next_layer().async_flush(
+ BOOST_ASIO_MOVE_CAST(WriteHandler)(handler));
   }
 
   /// Write the given data to the stream. Returns the number of bytes written.
@@ -148,10 +152,13 @@
   /// Start an asynchronous write. The data being written must be valid for the
   /// lifetime of the asynchronous operation.
   template <typename ConstBufferSequence, typename WriteHandler>
- void async_write_some(const ConstBufferSequence& buffers,
- WriteHandler handler)
+ BOOST_ASIO_INITFN_RESULT_TYPE(WriteHandler,
+ void (boost::system::error_code, std::size_t))
+ async_write_some(const ConstBufferSequence& buffers,
+ BOOST_ASIO_MOVE_ARG(WriteHandler) handler)
   {
- stream_impl_.async_write_some(buffers, handler);
+ return stream_impl_.async_write_some(buffers,
+ BOOST_ASIO_MOVE_CAST(WriteHandler)(handler));
   }
 
   /// Fill the buffer with some data. Returns the number of bytes placed in the
@@ -170,9 +177,11 @@
 
   /// Start an asynchronous fill.
   template <typename ReadHandler>
- void async_fill(ReadHandler handler)
+ BOOST_ASIO_INITFN_RESULT_TYPE(ReadHandler,
+ void (boost::system::error_code, std::size_t))
+ async_fill(BOOST_ASIO_MOVE_ARG(ReadHandler) handler)
   {
- stream_impl_.async_fill(handler);
+ return stream_impl_.async_fill(BOOST_ASIO_MOVE_CAST(ReadHandler)(handler));
   }
 
   /// Read some data from the stream. Returns the number of bytes read. Throws
@@ -195,10 +204,13 @@
   /// Start an asynchronous read. The buffer into which the data will be read
   /// must be valid for the lifetime of the asynchronous operation.
   template <typename MutableBufferSequence, typename ReadHandler>
- void async_read_some(const MutableBufferSequence& buffers,
- ReadHandler handler)
+ BOOST_ASIO_INITFN_RESULT_TYPE(ReadHandler,
+ void (boost::system::error_code, std::size_t))
+ async_read_some(const MutableBufferSequence& buffers,
+ BOOST_ASIO_MOVE_ARG(ReadHandler) handler)
   {
- stream_impl_.async_read_some(buffers, handler);
+ return stream_impl_.async_read_some(buffers,
+ BOOST_ASIO_MOVE_CAST(ReadHandler)(handler));
   }
 
   /// Peek at the incoming data on the stream. Returns the number of bytes read.

Modified: trunk/boost/asio/buffered_write_stream.hpp
==============================================================================
--- trunk/boost/asio/buffered_write_stream.hpp Thu Sep 19 17:15:15 2013 (r85797)
+++ trunk/boost/asio/buffered_write_stream.hpp 2013-09-20 08:00:44 EDT (Fri, 20 Sep 2013) (r85798)
@@ -118,156 +118,37 @@
   /// Flush all data from the buffer to the next layer. Returns the number of
   /// bytes written to the next layer on the last write operation. Throws an
   /// exception on failure.
- std::size_t flush()
- {
- std::size_t bytes_written = write(next_layer_,
- buffer(storage_.data(), storage_.size()));
- storage_.consume(bytes_written);
- return bytes_written;
- }
+ std::size_t flush();
 
   /// Flush all data from the buffer to the next layer. Returns the number of
   /// bytes written to the next layer on the last write operation, or 0 if an
   /// error occurred.
- std::size_t flush(boost::system::error_code& ec)
- {
- std::size_t bytes_written = write(next_layer_,
- buffer(storage_.data(), storage_.size()),
- transfer_all(), ec);
- storage_.consume(bytes_written);
- return bytes_written;
- }
-
- template <typename WriteHandler>
- class flush_handler
- {
- public:
- flush_handler(boost::asio::io_service& io_service,
- detail::buffered_stream_storage& storage, WriteHandler handler)
- : io_service_(io_service),
- storage_(storage),
- handler_(handler)
- {
- }
-
- void operator()(const boost::system::error_code& ec,
- std::size_t bytes_written)
- {
- storage_.consume(bytes_written);
- io_service_.dispatch(detail::bind_handler(handler_, ec, bytes_written));
- }
-
- private:
- boost::asio::io_service& io_service_;
- detail::buffered_stream_storage& storage_;
- WriteHandler handler_;
- };
+ std::size_t flush(boost::system::error_code& ec);
 
   /// Start an asynchronous flush.
   template <typename WriteHandler>
- void async_flush(WriteHandler handler)
- {
- async_write(next_layer_, buffer(storage_.data(), storage_.size()),
- flush_handler<WriteHandler>(get_io_service(), storage_, handler));
- }
+ BOOST_ASIO_INITFN_RESULT_TYPE(WriteHandler,
+ void (boost::system::error_code, std::size_t))
+ async_flush(BOOST_ASIO_MOVE_ARG(WriteHandler) handler);
 
   /// Write the given data to the stream. Returns the number of bytes written.
   /// Throws an exception on failure.
   template <typename ConstBufferSequence>
- std::size_t write_some(const ConstBufferSequence& buffers)
- {
- if (boost::asio::buffer_size(buffers) == 0)
- return 0;
-
- if (storage_.size() == storage_.capacity())
- flush();
-
- return copy(buffers);
- }
+ std::size_t write_some(const ConstBufferSequence& buffers);
 
   /// Write the given data to the stream. Returns the number of bytes written,
   /// or 0 if an error occurred and the error handler did not throw.
   template <typename ConstBufferSequence>
   std::size_t write_some(const ConstBufferSequence& buffers,
- boost::system::error_code& ec)
- {
- ec = boost::system::error_code();
-
- if (boost::asio::buffer_size(buffers) == 0)
- return 0;
-
- if (storage_.size() == storage_.capacity() && !flush(ec))
- return 0;
-
- return copy(buffers);
- }
-
- template <typename ConstBufferSequence, typename WriteHandler>
- class write_some_handler
- {
- public:
- write_some_handler(boost::asio::io_service& io_service,
- detail::buffered_stream_storage& storage,
- const ConstBufferSequence& buffers, WriteHandler handler)
- : io_service_(io_service),
- storage_(storage),
- buffers_(buffers),
- handler_(handler)
- {
- }
-
- void operator()(const boost::system::error_code& ec, std::size_t)
- {
- if (ec)
- {
- std::size_t length = 0;
- io_service_.dispatch(detail::bind_handler(handler_, ec, length));
- }
- else
- {
- std::size_t orig_size = storage_.size();
- std::size_t space_avail = storage_.capacity() - orig_size;
- std::size_t bytes_avail = boost::asio::buffer_size(buffers_);
- std::size_t length = bytes_avail < space_avail
- ? bytes_avail : space_avail;
- storage_.resize(orig_size + length);
- std::size_t bytes_copied = boost::asio::buffer_copy(
- storage_.data() + orig_size, buffers_, length);
-
- io_service_.dispatch(detail::bind_handler(handler_, ec, bytes_copied));
- }
- }
-
- private:
- boost::asio::io_service& io_service_;
- detail::buffered_stream_storage& storage_;
- ConstBufferSequence buffers_;
- WriteHandler handler_;
- };
+ boost::system::error_code& ec);
 
   /// Start an asynchronous write. The data being written must be valid for the
   /// lifetime of the asynchronous operation.
   template <typename ConstBufferSequence, typename WriteHandler>
- void async_write_some(const ConstBufferSequence& buffers,
- WriteHandler handler)
- {
- if (boost::asio::buffer_size(buffers) == 0)
- {
- get_io_service().post(detail::bind_handler(
- handler, boost::system::error_code(), 0));
- }
- else if (storage_.size() == storage_.capacity())
- {
- async_flush(write_some_handler<ConstBufferSequence, WriteHandler>(
- get_io_service(), storage_, buffers, handler));
- }
- else
- {
- std::size_t bytes_copied = copy(buffers);
- get_io_service().post(detail::bind_handler(
- handler, boost::system::error_code(), bytes_copied));
- }
- }
+ BOOST_ASIO_INITFN_RESULT_TYPE(WriteHandler,
+ void (boost::system::error_code, std::size_t))
+ async_write_some(const ConstBufferSequence& buffers,
+ BOOST_ASIO_MOVE_ARG(WriteHandler) handler);
 
   /// Read some data from the stream. Returns the number of bytes read. Throws
   /// an exception on failure.
@@ -289,10 +170,20 @@
   /// Start an asynchronous read. The buffer into which the data will be read
   /// must be valid for the lifetime of the asynchronous operation.
   template <typename MutableBufferSequence, typename ReadHandler>
- void async_read_some(const MutableBufferSequence& buffers,
- ReadHandler handler)
- {
- next_layer_.async_read_some(buffers, handler);
+ BOOST_ASIO_INITFN_RESULT_TYPE(ReadHandler,
+ void (boost::system::error_code, std::size_t))
+ async_read_some(const MutableBufferSequence& buffers,
+ BOOST_ASIO_MOVE_ARG(ReadHandler) handler)
+ {
+ detail::async_result_init<
+ ReadHandler, void (boost::system::error_code, std::size_t)> init(
+ BOOST_ASIO_MOVE_CAST(ReadHandler)(handler));
+
+ next_layer_.async_read_some(buffers,
+ BOOST_ASIO_MOVE_CAST(BOOST_ASIO_HANDLER_TYPE(ReadHandler,
+ void (boost::system::error_code, std::size_t)))(init.handler));
+
+ return init.result.get();
   }
 
   /// Peek at the incoming data on the stream. Returns the number of bytes read.
@@ -328,16 +219,7 @@
   /// Copy data into the internal buffer from the specified source buffer.
   /// Returns the number of bytes copied.
   template <typename ConstBufferSequence>
- std::size_t copy(const ConstBufferSequence& buffers)
- {
- std::size_t orig_size = storage_.size();
- std::size_t space_avail = storage_.capacity() - orig_size;
- std::size_t bytes_avail = boost::asio::buffer_size(buffers);
- std::size_t length = bytes_avail < space_avail ? bytes_avail : space_avail;
- storage_.resize(orig_size + length);
- return boost::asio::buffer_copy(
- storage_.data() + orig_size, buffers, length);
- }
+ std::size_t copy(const ConstBufferSequence& buffers);
 
   /// The next layer.
   Stream next_layer_;
@@ -351,4 +233,6 @@
 
 #include <boost/asio/detail/pop_options.hpp>
 
+#include <boost/asio/impl/buffered_write_stream.hpp>
+
 #endif // BOOST_ASIO_BUFFERED_WRITE_STREAM_HPP

Added: trunk/boost/asio/impl/buffered_read_stream.hpp
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ trunk/boost/asio/impl/buffered_read_stream.hpp 2013-09-20 08:00:44 EDT (Fri, 20 Sep 2013) (r85798)
@@ -0,0 +1,360 @@
+//
+// impl/buffered_read_stream.hpp
+// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+//
+// Copyright (c) 2003-2013 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_BUFFERED_READ_STREAM_HPP
+#define BOOST_ASIO_IMPL_BUFFERED_READ_STREAM_HPP
+
+#if defined(_MSC_VER) && (_MSC_VER >= 1200)
+# pragma once
+#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
+
+#include <boost/asio/detail/handler_alloc_helpers.hpp>
+#include <boost/asio/detail/handler_cont_helpers.hpp>
+#include <boost/asio/detail/handler_invoke_helpers.hpp>
+#include <boost/asio/detail/handler_type_requirements.hpp>
+
+#include <boost/asio/detail/push_options.hpp>
+
+namespace boost {
+namespace asio {
+
+template <typename Stream>
+std::size_t buffered_read_stream<Stream>::fill()
+{
+ detail::buffer_resize_guard<detail::buffered_stream_storage>
+ resize_guard(storage_);
+ std::size_t previous_size = storage_.size();
+ storage_.resize(storage_.capacity());
+ storage_.resize(previous_size + next_layer_.read_some(buffer(
+ storage_.data() + previous_size,
+ storage_.size() - previous_size)));
+ resize_guard.commit();
+ return storage_.size() - previous_size;
+}
+
+template <typename Stream>
+std::size_t buffered_read_stream<Stream>::fill(boost::system::error_code& ec)
+{
+ detail::buffer_resize_guard<detail::buffered_stream_storage>
+ resize_guard(storage_);
+ std::size_t previous_size = storage_.size();
+ storage_.resize(storage_.capacity());
+ storage_.resize(previous_size + next_layer_.read_some(buffer(
+ storage_.data() + previous_size,
+ storage_.size() - previous_size),
+ ec));
+ resize_guard.commit();
+ return storage_.size() - previous_size;
+}
+
+namespace detail
+{
+ template <typename ReadHandler>
+ class buffered_fill_handler
+ {
+ public:
+ buffered_fill_handler(detail::buffered_stream_storage& storage,
+ std::size_t previous_size, ReadHandler& handler)
+ : storage_(storage),
+ previous_size_(previous_size),
+ handler_(BOOST_ASIO_MOVE_CAST(ReadHandler)(handler))
+ {
+ }
+
+#if defined(BOOST_ASIO_HAS_MOVE)
+ buffered_fill_handler(const buffered_fill_handler& other)
+ : storage_(other.storage_),
+ previous_size_(other.previous_size_),
+ handler_(other.handler_)
+ {
+ }
+
+ buffered_fill_handler(buffered_fill_handler&& other)
+ : storage_(other.storage_),
+ previous_size_(other.previous_size_),
+ handler_(BOOST_ASIO_MOVE_CAST(ReadHandler)(other.handler_))
+ {
+ }
+#endif // defined(BOOST_ASIO_HAS_MOVE)
+
+ void operator()(const boost::system::error_code& ec,
+ const std::size_t bytes_transferred)
+ {
+ storage_.resize(previous_size_ + bytes_transferred);
+ handler_(ec, bytes_transferred);
+ }
+
+ //private:
+ detail::buffered_stream_storage& storage_;
+ std::size_t previous_size_;
+ ReadHandler handler_;
+ };
+
+ template <typename ReadHandler>
+ inline void* asio_handler_allocate(std::size_t size,
+ buffered_fill_handler<ReadHandler>* this_handler)
+ {
+ return boost_asio_handler_alloc_helpers::allocate(
+ size, this_handler->handler_);
+ }
+
+ template <typename ReadHandler>
+ inline void asio_handler_deallocate(void* pointer, std::size_t size,
+ buffered_fill_handler<ReadHandler>* this_handler)
+ {
+ boost_asio_handler_alloc_helpers::deallocate(
+ pointer, size, this_handler->handler_);
+ }
+
+ template <typename ReadHandler>
+ inline bool asio_handler_is_continuation(
+ buffered_fill_handler<ReadHandler>* this_handler)
+ {
+ return boost_asio_handler_cont_helpers::is_continuation(
+ this_handler->handler_);
+ }
+
+ template <typename Function, typename ReadHandler>
+ inline void asio_handler_invoke(Function& function,
+ buffered_fill_handler<ReadHandler>* this_handler)
+ {
+ boost_asio_handler_invoke_helpers::invoke(
+ function, this_handler->handler_);
+ }
+
+ template <typename Function, typename ReadHandler>
+ inline void asio_handler_invoke(const Function& function,
+ buffered_fill_handler<ReadHandler>* this_handler)
+ {
+ boost_asio_handler_invoke_helpers::invoke(
+ function, this_handler->handler_);
+ }
+} // namespace detail
+
+template <typename Stream>
+template <typename ReadHandler>
+BOOST_ASIO_INITFN_RESULT_TYPE(ReadHandler,
+ void (boost::system::error_code, std::size_t))
+buffered_read_stream<Stream>::async_fill(
+ BOOST_ASIO_MOVE_ARG(ReadHandler) handler)
+{
+ // If you get an error on the following line it means that your handler does
+ // not meet the documented type requirements for a ReadHandler.
+ BOOST_ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check;
+
+ detail::async_result_init<
+ ReadHandler, void (boost::system::error_code, std::size_t)> init(
+ BOOST_ASIO_MOVE_CAST(ReadHandler)(handler));
+
+ std::size_t previous_size = storage_.size();
+ storage_.resize(storage_.capacity());
+ next_layer_.async_read_some(
+ buffer(
+ storage_.data() + previous_size,
+ storage_.size() - previous_size),
+ detail::buffered_fill_handler<BOOST_ASIO_HANDLER_TYPE(
+ ReadHandler, void (boost::system::error_code, std::size_t))>(
+ storage_, previous_size, init.handler));
+
+ return init.result.get();
+}
+
+template <typename Stream>
+template <typename MutableBufferSequence>
+std::size_t buffered_read_stream<Stream>::read_some(
+ const MutableBufferSequence& buffers)
+{
+ if (boost::asio::buffer_size(buffers) == 0)
+ return 0;
+
+ if (storage_.empty())
+ this->fill();
+
+ return this->copy(buffers);
+}
+
+template <typename Stream>
+template <typename MutableBufferSequence>
+std::size_t buffered_read_stream<Stream>::read_some(
+ const MutableBufferSequence& buffers, boost::system::error_code& ec)
+{
+ ec = boost::system::error_code();
+
+ if (boost::asio::buffer_size(buffers) == 0)
+ return 0;
+
+ if (storage_.empty() && !this->fill(ec))
+ return 0;
+
+ return this->copy(buffers);
+}
+
+namespace detail
+{
+ template <typename MutableBufferSequence, typename ReadHandler>
+ class buffered_read_some_handler
+ {
+ public:
+ buffered_read_some_handler(detail::buffered_stream_storage& storage,
+ const MutableBufferSequence& buffers, ReadHandler& handler)
+ : storage_(storage),
+ buffers_(buffers),
+ handler_(handler)
+ {
+ }
+
+#if defined(BOOST_ASIO_HAS_MOVE)
+ buffered_read_some_handler(const buffered_read_some_handler& other)
+ : storage_(other.storage_),
+ buffers_(other.buffers_),
+ handler_(other.handler_)
+ {
+ }
+
+ buffered_read_some_handler(buffered_read_some_handler&& other)
+ : storage_(other.storage_),
+ buffers_(other.buffers_),
+ handler_(BOOST_ASIO_MOVE_CAST(ReadHandler)(other.handler_))
+ {
+ }
+#endif // defined(BOOST_ASIO_HAS_MOVE)
+
+ void operator()(const boost::system::error_code& ec, std::size_t)
+ {
+ if (ec || storage_.empty())
+ {
+ const std::size_t length = 0;
+ handler_(ec, length);
+ }
+ else
+ {
+ const std::size_t bytes_copied = boost::asio::buffer_copy(
+ buffers_, storage_.data(), storage_.size());
+ storage_.consume(bytes_copied);
+ handler_(ec, bytes_copied);
+ }
+ }
+
+ //private:
+ detail::buffered_stream_storage& storage_;
+ MutableBufferSequence buffers_;
+ ReadHandler handler_;
+ };
+
+ template <typename MutableBufferSequence, typename ReadHandler>
+ inline void* asio_handler_allocate(std::size_t size,
+ buffered_read_some_handler<
+ MutableBufferSequence, ReadHandler>* this_handler)
+ {
+ return boost_asio_handler_alloc_helpers::allocate(
+ size, this_handler->handler_);
+ }
+
+ template <typename MutableBufferSequence, typename ReadHandler>
+ inline void asio_handler_deallocate(void* pointer, std::size_t size,
+ buffered_read_some_handler<
+ MutableBufferSequence, ReadHandler>* this_handler)
+ {
+ boost_asio_handler_alloc_helpers::deallocate(
+ pointer, size, this_handler->handler_);
+ }
+
+ template <typename MutableBufferSequence, typename ReadHandler>
+ inline bool asio_handler_is_continuation(
+ buffered_read_some_handler<
+ MutableBufferSequence, ReadHandler>* this_handler)
+ {
+ return boost_asio_handler_cont_helpers::is_continuation(
+ this_handler->handler_);
+ }
+
+ template <typename Function, typename MutableBufferSequence,
+ typename ReadHandler>
+ inline void asio_handler_invoke(Function& function,
+ buffered_read_some_handler<
+ MutableBufferSequence, ReadHandler>* this_handler)
+ {
+ boost_asio_handler_invoke_helpers::invoke(
+ function, this_handler->handler_);
+ }
+
+ template <typename Function, typename MutableBufferSequence,
+ typename ReadHandler>
+ inline void asio_handler_invoke(const Function& function,
+ buffered_read_some_handler<
+ MutableBufferSequence, ReadHandler>* this_handler)
+ {
+ boost_asio_handler_invoke_helpers::invoke(
+ function, this_handler->handler_);
+ }
+} // namespace detail
+
+template <typename Stream>
+template <typename MutableBufferSequence, typename ReadHandler>
+BOOST_ASIO_INITFN_RESULT_TYPE(ReadHandler,
+ void (boost::system::error_code, std::size_t))
+buffered_read_stream<Stream>::async_read_some(
+ const MutableBufferSequence& buffers,
+ BOOST_ASIO_MOVE_ARG(ReadHandler) handler)
+{
+ // If you get an error on the following line it means that your handler does
+ // not meet the documented type requirements for a ReadHandler.
+ BOOST_ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check;
+
+ detail::async_result_init<
+ ReadHandler, void (boost::system::error_code, std::size_t)> init(
+ BOOST_ASIO_MOVE_CAST(ReadHandler)(handler));
+
+ if (boost::asio::buffer_size(buffers) == 0 || !storage_.empty())
+ {
+ next_layer_.async_read_some(boost::asio::mutable_buffers_1(0, 0),
+ detail::buffered_read_some_handler<
+ MutableBufferSequence, BOOST_ASIO_HANDLER_TYPE(
+ ReadHandler, void (boost::system::error_code, std::size_t))>(
+ storage_, buffers, init.handler));
+ }
+ else
+ {
+ this->async_fill(detail::buffered_read_some_handler<
+ MutableBufferSequence, BOOST_ASIO_HANDLER_TYPE(
+ ReadHandler, void (boost::system::error_code, std::size_t))>(
+ storage_, buffers, init.handler));
+ }
+
+ return init.result.get();
+}
+
+template <typename Stream>
+template <typename MutableBufferSequence>
+std::size_t buffered_read_stream<Stream>::peek(
+ const MutableBufferSequence& buffers)
+{
+ if (storage_.empty())
+ this->fill();
+ return this->peek_copy(buffers);
+}
+
+template <typename Stream>
+template <typename MutableBufferSequence>
+std::size_t buffered_read_stream<Stream>::peek(
+ const MutableBufferSequence& buffers, boost::system::error_code& ec)
+{
+ ec = boost::system::error_code();
+ if (storage_.empty() && !this->fill(ec))
+ return 0;
+ return this->peek_copy(buffers);
+}
+
+} // namespace asio
+} // namespace boost
+
+#include <boost/asio/detail/pop_options.hpp>
+
+#endif // BOOST_ASIO_IMPL_BUFFERED_READ_STREAM_HPP

Added: trunk/boost/asio/impl/buffered_write_stream.hpp
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ trunk/boost/asio/impl/buffered_write_stream.hpp 2013-09-20 08:00:44 EDT (Fri, 20 Sep 2013) (r85798)
@@ -0,0 +1,340 @@
+//
+// impl/buffered_write_stream.hpp
+// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+//
+// Copyright (c) 2003-2013 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_BUFFERED_WRITE_STREAM_HPP
+#define BOOST_ASIO_IMPL_BUFFERED_WRITE_STREAM_HPP
+
+#if defined(_MSC_VER) && (_MSC_VER >= 1200)
+# pragma once
+#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
+
+#include <boost/asio/detail/handler_alloc_helpers.hpp>
+#include <boost/asio/detail/handler_cont_helpers.hpp>
+#include <boost/asio/detail/handler_invoke_helpers.hpp>
+#include <boost/asio/detail/handler_type_requirements.hpp>
+
+#include <boost/asio/detail/push_options.hpp>
+
+namespace boost {
+namespace asio {
+
+template <typename Stream>
+std::size_t buffered_write_stream<Stream>::flush()
+{
+ std::size_t bytes_written = write(next_layer_,
+ buffer(storage_.data(), storage_.size()));
+ storage_.consume(bytes_written);
+ return bytes_written;
+}
+
+template <typename Stream>
+std::size_t buffered_write_stream<Stream>::flush(boost::system::error_code& ec)
+{
+ std::size_t bytes_written = write(next_layer_,
+ buffer(storage_.data(), storage_.size()),
+ transfer_all(), ec);
+ storage_.consume(bytes_written);
+ return bytes_written;
+}
+
+namespace detail
+{
+ template <typename WriteHandler>
+ class buffered_flush_handler
+ {
+ public:
+ buffered_flush_handler(detail::buffered_stream_storage& storage,
+ WriteHandler& handler)
+ : storage_(storage),
+ handler_(handler)
+ {
+ }
+
+#if defined(BOOST_ASIO_HAS_MOVE)
+ buffered_flush_handler(const buffered_flush_handler& other)
+ : storage_(other.storage_),
+ handler_(other.handler_)
+ {
+ }
+
+ buffered_flush_handler(buffered_flush_handler&& other)
+ : storage_(other.storage_),
+ handler_(BOOST_ASIO_MOVE_CAST(WriteHandler)(other.handler_))
+ {
+ }
+#endif // defined(BOOST_ASIO_HAS_MOVE)
+
+ void operator()(const boost::system::error_code& ec,
+ const std::size_t bytes_written)
+ {
+ storage_.consume(bytes_written);
+ handler_(ec, bytes_written);
+ }
+
+ //private:
+ detail::buffered_stream_storage& storage_;
+ WriteHandler handler_;
+ };
+
+ template <typename WriteHandler>
+ inline void* asio_handler_allocate(std::size_t size,
+ buffered_flush_handler<WriteHandler>* this_handler)
+ {
+ return boost_asio_handler_alloc_helpers::allocate(
+ size, this_handler->handler_);
+ }
+
+ template <typename WriteHandler>
+ inline void asio_handler_deallocate(void* pointer, std::size_t size,
+ buffered_flush_handler<WriteHandler>* this_handler)
+ {
+ boost_asio_handler_alloc_helpers::deallocate(
+ pointer, size, this_handler->handler_);
+ }
+
+ template <typename WriteHandler>
+ inline bool asio_handler_is_continuation(
+ buffered_flush_handler<WriteHandler>* this_handler)
+ {
+ return boost_asio_handler_cont_helpers::is_continuation(
+ this_handler->handler_);
+ }
+
+ template <typename Function, typename WriteHandler>
+ inline void asio_handler_invoke(Function& function,
+ buffered_flush_handler<WriteHandler>* this_handler)
+ {
+ boost_asio_handler_invoke_helpers::invoke(
+ function, this_handler->handler_);
+ }
+
+ template <typename Function, typename WriteHandler>
+ inline void asio_handler_invoke(const Function& function,
+ buffered_flush_handler<WriteHandler>* this_handler)
+ {
+ boost_asio_handler_invoke_helpers::invoke(
+ function, this_handler->handler_);
+ }
+}
+
+template <typename Stream>
+template <typename WriteHandler>
+BOOST_ASIO_INITFN_RESULT_TYPE(WriteHandler,
+ void (boost::system::error_code, std::size_t))
+buffered_write_stream<Stream>::async_flush(
+ BOOST_ASIO_MOVE_ARG(WriteHandler) handler)
+{
+ // If you get an error on the following line it means that your handler does
+ // not meet the documented type requirements for a WriteHandler.
+ BOOST_ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check;
+
+ detail::async_result_init<
+ WriteHandler, void (boost::system::error_code, std::size_t)> init(
+ BOOST_ASIO_MOVE_CAST(WriteHandler)(handler));
+
+ async_write(next_layer_, buffer(storage_.data(), storage_.size()),
+ detail::buffered_flush_handler<BOOST_ASIO_HANDLER_TYPE(
+ WriteHandler, void (boost::system::error_code, std::size_t))>(
+ storage_, init.handler));
+
+ return init.result.get();
+}
+
+template <typename Stream>
+template <typename ConstBufferSequence>
+std::size_t buffered_write_stream<Stream>::write_some(
+ const ConstBufferSequence& buffers)
+{
+ if (boost::asio::buffer_size(buffers) == 0)
+ return 0;
+
+ if (storage_.size() == storage_.capacity())
+ this->flush();
+
+ return this->copy(buffers);
+}
+
+template <typename Stream>
+template <typename ConstBufferSequence>
+std::size_t buffered_write_stream<Stream>::write_some(
+ const ConstBufferSequence& buffers, boost::system::error_code& ec)
+{
+ ec = boost::system::error_code();
+
+ if (boost::asio::buffer_size(buffers) == 0)
+ return 0;
+
+ if (storage_.size() == storage_.capacity() && !flush(ec))
+ return 0;
+
+ return this->copy(buffers);
+}
+
+namespace detail
+{
+ template <typename ConstBufferSequence, typename WriteHandler>
+ class buffered_write_some_handler
+ {
+ public:
+ buffered_write_some_handler(detail::buffered_stream_storage& storage,
+ const ConstBufferSequence& buffers, WriteHandler& handler)
+ : storage_(storage),
+ buffers_(buffers),
+ handler_(handler)
+ {
+ }
+
+#if defined(BOOST_ASIO_HAS_MOVE)
+ buffered_write_some_handler(const buffered_write_some_handler& other)
+ : storage_(other.storage_),
+ buffers_(other.buffers_),
+ handler_(other.handler_)
+ {
+ }
+
+ buffered_write_some_handler(buffered_write_some_handler&& other)
+ : storage_(other.storage_),
+ buffers_(other.buffers_),
+ handler_(BOOST_ASIO_MOVE_CAST(WriteHandler)(other.handler_))
+ {
+ }
+#endif // defined(BOOST_ASIO_HAS_MOVE)
+
+ void operator()(const boost::system::error_code& ec, std::size_t)
+ {
+ if (ec)
+ {
+ const std::size_t length = 0;
+ handler_(ec, length);
+ }
+ else
+ {
+ std::size_t orig_size = storage_.size();
+ std::size_t space_avail = storage_.capacity() - orig_size;
+ std::size_t bytes_avail = boost::asio::buffer_size(buffers_);
+ std::size_t length = bytes_avail < space_avail
+ ? bytes_avail : space_avail;
+ storage_.resize(orig_size + length);
+ const std::size_t bytes_copied = boost::asio::buffer_copy(
+ storage_.data() + orig_size, buffers_, length);
+ handler_(ec, bytes_copied);
+ }
+ }
+
+ //private:
+ detail::buffered_stream_storage& storage_;
+ ConstBufferSequence buffers_;
+ WriteHandler handler_;
+ };
+
+ template <typename ConstBufferSequence, typename WriteHandler>
+ inline void* asio_handler_allocate(std::size_t size,
+ buffered_write_some_handler<
+ ConstBufferSequence, WriteHandler>* this_handler)
+ {
+ return boost_asio_handler_alloc_helpers::allocate(
+ size, this_handler->handler_);
+ }
+
+ template <typename ConstBufferSequence, typename WriteHandler>
+ inline void asio_handler_deallocate(void* pointer, std::size_t size,
+ buffered_write_some_handler<
+ ConstBufferSequence, WriteHandler>* this_handler)
+ {
+ boost_asio_handler_alloc_helpers::deallocate(
+ pointer, size, this_handler->handler_);
+ }
+
+ template <typename ConstBufferSequence, typename WriteHandler>
+ inline bool asio_handler_is_continuation(
+ buffered_write_some_handler<
+ ConstBufferSequence, WriteHandler>* this_handler)
+ {
+ return boost_asio_handler_cont_helpers::is_continuation(
+ this_handler->handler_);
+ }
+
+ template <typename Function, typename ConstBufferSequence,
+ typename WriteHandler>
+ inline void asio_handler_invoke(Function& function,
+ buffered_write_some_handler<
+ ConstBufferSequence, WriteHandler>* this_handler)
+ {
+ boost_asio_handler_invoke_helpers::invoke(
+ function, this_handler->handler_);
+ }
+
+ template <typename Function, typename ConstBufferSequence,
+ typename WriteHandler>
+ inline void asio_handler_invoke(const Function& function,
+ buffered_write_some_handler<
+ ConstBufferSequence, WriteHandler>* this_handler)
+ {
+ boost_asio_handler_invoke_helpers::invoke(
+ function, this_handler->handler_);
+ }
+} // namespace detail
+
+template <typename Stream>
+template <typename ConstBufferSequence, typename WriteHandler>
+BOOST_ASIO_INITFN_RESULT_TYPE(WriteHandler,
+ void (boost::system::error_code, std::size_t))
+buffered_write_stream<Stream>::async_write_some(
+ const ConstBufferSequence& buffers,
+ BOOST_ASIO_MOVE_ARG(WriteHandler) handler)
+{
+ // If you get an error on the following line it means that your handler does
+ // not meet the documented type requirements for a WriteHandler.
+ BOOST_ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check;
+
+ detail::async_result_init<
+ WriteHandler, void (boost::system::error_code, std::size_t)> init(
+ BOOST_ASIO_MOVE_CAST(WriteHandler)(handler));
+
+ if (boost::asio::buffer_size(buffers) == 0
+ || storage_.size() < storage_.capacity())
+ {
+ next_layer_.async_write_some(boost::asio::const_buffers_1(0, 0),
+ detail::buffered_write_some_handler<
+ ConstBufferSequence, BOOST_ASIO_HANDLER_TYPE(
+ WriteHandler, void (boost::system::error_code, std::size_t))>(
+ storage_, buffers, init.handler));
+ }
+ else
+ {
+ this->async_flush(detail::buffered_write_some_handler<
+ ConstBufferSequence, BOOST_ASIO_HANDLER_TYPE(
+ WriteHandler, void (boost::system::error_code, std::size_t))>(
+ storage_, buffers, init.handler));
+ }
+
+ return init.result.get();
+}
+
+template <typename Stream>
+template <typename ConstBufferSequence>
+std::size_t buffered_write_stream<Stream>::copy(
+ const ConstBufferSequence& buffers)
+{
+ std::size_t orig_size = storage_.size();
+ std::size_t space_avail = storage_.capacity() - orig_size;
+ std::size_t bytes_avail = boost::asio::buffer_size(buffers);
+ std::size_t length = bytes_avail < space_avail ? bytes_avail : space_avail;
+ storage_.resize(orig_size + length);
+ return boost::asio::buffer_copy(
+ storage_.data() + orig_size, buffers, length);
+}
+
+} // namespace asio
+} // namespace boost
+
+#include <boost/asio/detail/pop_options.hpp>
+
+#endif // BOOST_ASIO_IMPL_BUFFERED_WRITE_STREAM_HPP

Modified: trunk/libs/asio/test/buffered_read_stream.cpp
==============================================================================
--- trunk/libs/asio/test/buffered_read_stream.cpp Thu Sep 19 17:15:15 2013 (r85797)
+++ trunk/libs/asio/test/buffered_read_stream.cpp 2013-09-20 08:00:44 EDT (Fri, 20 Sep 2013) (r85798)
@@ -17,12 +17,19 @@
 #include <boost/asio/buffered_read_stream.hpp>
 
 #include <cstring>
+#include "archetypes/async_result.hpp"
 #include <boost/asio/buffer.hpp>
 #include <boost/asio/io_service.hpp>
 #include <boost/asio/ip/tcp.hpp>
 #include <boost/system/system_error.hpp>
 #include "unit_test.hpp"
 
+#if defined(BOOST_ASIO_HAS_BOOST_ARRAY)
+# include <boost/array.hpp>
+#else // defined(BOOST_ASIO_HAS_BOOST_ARRAY)
+# include <array>
+#endif // defined(BOOST_ASIO_HAS_BOOST_ARRAY)
+
 #if defined(BOOST_ASIO_HAS_BOOST_BIND)
 # include <boost/bind.hpp>
 #else // defined(BOOST_ASIO_HAS_BOOST_BIND)
@@ -32,6 +39,107 @@
 typedef boost::asio::buffered_read_stream<
     boost::asio::ip::tcp::socket> stream_type;
 
+void write_some_handler(const boost::system::error_code&, std::size_t)
+{
+}
+
+void fill_handler(const boost::system::error_code&, std::size_t)
+{
+}
+
+void read_some_handler(const boost::system::error_code&, std::size_t)
+{
+}
+
+void test_compile()
+{
+#if defined(BOOST_ASIO_HAS_BOOST_ARRAY)
+ using boost::array;
+#else // defined(BOOST_ASIO_HAS_BOOST_ARRAY)
+ using std::array;
+#endif // defined(BOOST_ASIO_HAS_BOOST_ARRAY)
+
+ using namespace boost::asio;
+
+ try
+ {
+ io_service ios;
+ char mutable_char_buffer[128] = "";
+ const char const_char_buffer[128] = "";
+ array<boost::asio::mutable_buffer, 2> mutable_buffers = {{
+ boost::asio::buffer(mutable_char_buffer, 10),
+ boost::asio::buffer(mutable_char_buffer + 10, 10) }};
+ array<boost::asio::const_buffer, 2> const_buffers = {{
+ boost::asio::buffer(const_char_buffer, 10),
+ boost::asio::buffer(const_char_buffer + 10, 10) }};
+ archetypes::lazy_handler lazy;
+ boost::system::error_code ec;
+
+ stream_type stream1(ios);
+ stream_type stream2(ios, 1024);
+
+ io_service& ios_ref = stream1.get_io_service();
+ (void)ios_ref;
+
+ stream_type::lowest_layer_type& lowest_layer = stream1.lowest_layer();
+ (void)lowest_layer;
+
+ stream1.write_some(buffer(mutable_char_buffer));
+ stream1.write_some(buffer(const_char_buffer));
+ stream1.write_some(mutable_buffers);
+ stream1.write_some(const_buffers);
+ stream1.write_some(null_buffers());
+ stream1.write_some(buffer(mutable_char_buffer), ec);
+ stream1.write_some(buffer(const_char_buffer), ec);
+ stream1.write_some(mutable_buffers, ec);
+ stream1.write_some(const_buffers, ec);
+ stream1.write_some(null_buffers(), ec);
+
+ stream1.async_write_some(buffer(mutable_char_buffer), &write_some_handler);
+ stream1.async_write_some(buffer(const_char_buffer), &write_some_handler);
+ stream1.async_write_some(mutable_buffers, &write_some_handler);
+ stream1.async_write_some(const_buffers, &write_some_handler);
+ stream1.async_write_some(null_buffers(), &write_some_handler);
+ int i1 = stream1.async_write_some(buffer(mutable_char_buffer), lazy);
+ (void)i1;
+ int i2 = stream1.async_write_some(buffer(const_char_buffer), lazy);
+ (void)i2;
+ int i3 = stream1.async_write_some(mutable_buffers, lazy);
+ (void)i3;
+ int i4 = stream1.async_write_some(const_buffers, lazy);
+ (void)i4;
+ int i5 = stream1.async_write_some(null_buffers(), lazy);
+ (void)i5;
+
+ stream1.fill();
+ stream1.fill(ec);
+
+ stream1.async_fill(&fill_handler);
+ int i6 = stream1.async_fill(lazy);
+ (void)i6;
+
+ stream1.read_some(buffer(mutable_char_buffer));
+ stream1.read_some(mutable_buffers);
+ stream1.read_some(null_buffers());
+ stream1.read_some(buffer(mutable_char_buffer), ec);
+ stream1.read_some(mutable_buffers, ec);
+ stream1.read_some(null_buffers(), ec);
+
+ stream1.async_read_some(buffer(mutable_char_buffer), &read_some_handler);
+ stream1.async_read_some(mutable_buffers, &read_some_handler);
+ stream1.async_read_some(null_buffers(), &read_some_handler);
+ int i7 = stream1.async_read_some(buffer(mutable_char_buffer), lazy);
+ (void)i7;
+ int i8 = stream1.async_read_some(mutable_buffers, lazy);
+ (void)i8;
+ int i9 = stream1.async_read_some(null_buffers(), lazy);
+ (void)i9;
+ }
+ catch (std::exception&)
+ {
+ }
+}
+
 void test_sync_operations()
 {
   using namespace std; // For memcmp.
@@ -224,6 +332,7 @@
 BOOST_ASIO_TEST_SUITE
 (
   "buffered_read_stream",
+ BOOST_ASIO_TEST_CASE(test_compile)
   BOOST_ASIO_TEST_CASE(test_sync_operations)
   BOOST_ASIO_TEST_CASE(test_async_operations)
 )

Modified: trunk/libs/asio/test/buffered_stream.cpp
==============================================================================
--- trunk/libs/asio/test/buffered_stream.cpp Thu Sep 19 17:15:15 2013 (r85797)
+++ trunk/libs/asio/test/buffered_stream.cpp 2013-09-20 08:00:44 EDT (Fri, 20 Sep 2013) (r85798)
@@ -17,12 +17,19 @@
 #include <boost/asio/buffered_stream.hpp>
 
 #include <cstring>
+#include "archetypes/async_result.hpp"
 #include <boost/asio/buffer.hpp>
 #include <boost/asio/io_service.hpp>
 #include <boost/asio/ip/tcp.hpp>
 #include <boost/system/system_error.hpp>
 #include "unit_test.hpp"
 
+#if defined(BOOST_ASIO_HAS_BOOST_ARRAY)
+# include <boost/array.hpp>
+#else // defined(BOOST_ASIO_HAS_BOOST_ARRAY)
+# include <array>
+#endif // defined(BOOST_ASIO_HAS_BOOST_ARRAY)
+
 #if defined(BOOST_ASIO_HAS_BOOST_BIND)
 # include <boost/bind.hpp>
 #else // defined(BOOST_ASIO_HAS_BOOST_BIND)
@@ -32,6 +39,118 @@
 typedef boost::asio::buffered_stream<
     boost::asio::ip::tcp::socket> stream_type;
 
+void write_some_handler(const boost::system::error_code&, std::size_t)
+{
+}
+
+void flush_handler(const boost::system::error_code&, std::size_t)
+{
+}
+
+void fill_handler(const boost::system::error_code&, std::size_t)
+{
+}
+
+void read_some_handler(const boost::system::error_code&, std::size_t)
+{
+}
+
+void test_compile()
+{
+#if defined(BOOST_ASIO_HAS_BOOST_ARRAY)
+ using boost::array;
+#else // defined(BOOST_ASIO_HAS_BOOST_ARRAY)
+ using std::array;
+#endif // defined(BOOST_ASIO_HAS_BOOST_ARRAY)
+
+ using namespace boost::asio;
+
+ try
+ {
+ io_service ios;
+ char mutable_char_buffer[128] = "";
+ const char const_char_buffer[128] = "";
+ array<boost::asio::mutable_buffer, 2> mutable_buffers = {{
+ boost::asio::buffer(mutable_char_buffer, 10),
+ boost::asio::buffer(mutable_char_buffer + 10, 10) }};
+ array<boost::asio::const_buffer, 2> const_buffers = {{
+ boost::asio::buffer(const_char_buffer, 10),
+ boost::asio::buffer(const_char_buffer + 10, 10) }};
+ archetypes::lazy_handler lazy;
+ boost::system::error_code ec;
+
+ stream_type stream1(ios);
+ stream_type stream2(ios, 1024, 1024);
+
+ io_service& ios_ref = stream1.get_io_service();
+ (void)ios_ref;
+
+ stream_type::lowest_layer_type& lowest_layer = stream1.lowest_layer();
+ (void)lowest_layer;
+
+ stream1.write_some(buffer(mutable_char_buffer));
+ stream1.write_some(buffer(const_char_buffer));
+ stream1.write_some(mutable_buffers);
+ stream1.write_some(const_buffers);
+ stream1.write_some(null_buffers());
+ stream1.write_some(buffer(mutable_char_buffer), ec);
+ stream1.write_some(buffer(const_char_buffer), ec);
+ stream1.write_some(mutable_buffers, ec);
+ stream1.write_some(const_buffers, ec);
+ stream1.write_some(null_buffers(), ec);
+
+ stream1.async_write_some(buffer(mutable_char_buffer), &write_some_handler);
+ stream1.async_write_some(buffer(const_char_buffer), &write_some_handler);
+ stream1.async_write_some(mutable_buffers, &write_some_handler);
+ stream1.async_write_some(const_buffers, &write_some_handler);
+ stream1.async_write_some(null_buffers(), &write_some_handler);
+ int i1 = stream1.async_write_some(buffer(mutable_char_buffer), lazy);
+ (void)i1;
+ int i2 = stream1.async_write_some(buffer(const_char_buffer), lazy);
+ (void)i2;
+ int i3 = stream1.async_write_some(mutable_buffers, lazy);
+ (void)i3;
+ int i4 = stream1.async_write_some(const_buffers, lazy);
+ (void)i4;
+ int i5 = stream1.async_write_some(null_buffers(), lazy);
+ (void)i5;
+
+ stream1.flush();
+ stream1.flush(ec);
+
+ stream1.async_flush(&flush_handler);
+ int i6 = stream1.async_flush(lazy);
+ (void)i6;
+
+ stream1.fill();
+ stream1.fill(ec);
+
+ stream1.async_fill(&fill_handler);
+ int i7 = stream1.async_fill(lazy);
+ (void)i7;
+
+ stream1.read_some(buffer(mutable_char_buffer));
+ stream1.read_some(mutable_buffers);
+ stream1.read_some(null_buffers());
+ stream1.read_some(buffer(mutable_char_buffer), ec);
+ stream1.read_some(mutable_buffers, ec);
+ stream1.read_some(null_buffers(), ec);
+
+ stream1.async_read_some(buffer(mutable_char_buffer), &read_some_handler);
+ stream1.async_read_some(mutable_buffers, &read_some_handler);
+ stream1.async_read_some(null_buffers(), &read_some_handler);
+ int i8 = stream1.async_read_some(buffer(mutable_char_buffer), lazy);
+ (void)i8;
+ int i9 = stream1.async_read_some(mutable_buffers, lazy);
+ (void)i9;
+ int i10 = stream1.async_read_some(null_buffers(), lazy);
+ (void)i10;
+ }
+ catch (std::exception&)
+ {
+ }
+}
+
 void test_sync_operations()
 {
   using namespace std; // For memcmp.
@@ -239,6 +358,7 @@
 BOOST_ASIO_TEST_SUITE
 (
   "buffered_stream",
+ BOOST_ASIO_TEST_CASE(test_compile)
   BOOST_ASIO_TEST_CASE(test_sync_operations)
   BOOST_ASIO_TEST_CASE(test_async_operations)
 )

Modified: trunk/libs/asio/test/buffered_write_stream.cpp
==============================================================================
--- trunk/libs/asio/test/buffered_write_stream.cpp Thu Sep 19 17:15:15 2013 (r85797)
+++ trunk/libs/asio/test/buffered_write_stream.cpp 2013-09-20 08:00:44 EDT (Fri, 20 Sep 2013) (r85798)
@@ -17,12 +17,19 @@
 #include <boost/asio/buffered_write_stream.hpp>
 
 #include <cstring>
+#include "archetypes/async_result.hpp"
 #include <boost/asio/buffer.hpp>
 #include <boost/asio/io_service.hpp>
 #include <boost/asio/ip/tcp.hpp>
 #include <boost/system/system_error.hpp>
 #include "unit_test.hpp"
 
+#if defined(BOOST_ASIO_HAS_BOOST_ARRAY)
+# include <boost/array.hpp>
+#else // defined(BOOST_ASIO_HAS_BOOST_ARRAY)
+# include <array>
+#endif // defined(BOOST_ASIO_HAS_BOOST_ARRAY)
+
 #if defined(BOOST_ASIO_HAS_BOOST_BIND)
 # include <boost/bind.hpp>
 #else // defined(BOOST_ASIO_HAS_BOOST_BIND)
@@ -32,6 +39,107 @@
 typedef boost::asio::buffered_write_stream<
     boost::asio::ip::tcp::socket> stream_type;
 
+void write_some_handler(const boost::system::error_code&, std::size_t)
+{
+}
+
+void flush_handler(const boost::system::error_code&, std::size_t)
+{
+}
+
+void read_some_handler(const boost::system::error_code&, std::size_t)
+{
+}
+
+void test_compile()
+{
+#if defined(BOOST_ASIO_HAS_BOOST_ARRAY)
+ using boost::array;
+#else // defined(BOOST_ASIO_HAS_BOOST_ARRAY)
+ using std::array;
+#endif // defined(BOOST_ASIO_HAS_BOOST_ARRAY)
+
+ using namespace boost::asio;
+
+ try
+ {
+ io_service ios;
+ char mutable_char_buffer[128] = "";
+ const char const_char_buffer[128] = "";
+ array<boost::asio::mutable_buffer, 2> mutable_buffers = {{
+ boost::asio::buffer(mutable_char_buffer, 10),
+ boost::asio::buffer(mutable_char_buffer + 10, 10) }};
+ array<boost::asio::const_buffer, 2> const_buffers = {{
+ boost::asio::buffer(const_char_buffer, 10),
+ boost::asio::buffer(const_char_buffer + 10, 10) }};
+ archetypes::lazy_handler lazy;
+ boost::system::error_code ec;
+
+ stream_type stream1(ios);
+ stream_type stream2(ios, 1024);
+
+ io_service& ios_ref = stream1.get_io_service();
+ (void)ios_ref;
+
+ stream_type::lowest_layer_type& lowest_layer = stream1.lowest_layer();
+ (void)lowest_layer;
+
+ stream1.write_some(buffer(mutable_char_buffer));
+ stream1.write_some(buffer(const_char_buffer));
+ stream1.write_some(mutable_buffers);
+ stream1.write_some(const_buffers);
+ stream1.write_some(null_buffers());
+ stream1.write_some(buffer(mutable_char_buffer), ec);
+ stream1.write_some(buffer(const_char_buffer), ec);
+ stream1.write_some(mutable_buffers, ec);
+ stream1.write_some(const_buffers, ec);
+ stream1.write_some(null_buffers(), ec);
+
+ stream1.async_write_some(buffer(mutable_char_buffer), &write_some_handler);
+ stream1.async_write_some(buffer(const_char_buffer), &write_some_handler);
+ stream1.async_write_some(mutable_buffers, &write_some_handler);
+ stream1.async_write_some(const_buffers, &write_some_handler);
+ stream1.async_write_some(null_buffers(), &write_some_handler);
+ int i1 = stream1.async_write_some(buffer(mutable_char_buffer), lazy);
+ (void)i1;
+ int i2 = stream1.async_write_some(buffer(const_char_buffer), lazy);
+ (void)i2;
+ int i3 = stream1.async_write_some(mutable_buffers, lazy);
+ (void)i3;
+ int i4 = stream1.async_write_some(const_buffers, lazy);
+ (void)i4;
+ int i5 = stream1.async_write_some(null_buffers(), lazy);
+ (void)i5;
+
+ stream1.flush();
+ stream1.flush(ec);
+
+ stream1.async_flush(&flush_handler);
+ int i6 = stream1.async_flush(lazy);
+ (void)i6;
+
+ stream1.read_some(buffer(mutable_char_buffer));
+ stream1.read_some(mutable_buffers);
+ stream1.read_some(null_buffers());
+ stream1.read_some(buffer(mutable_char_buffer), ec);
+ stream1.read_some(mutable_buffers, ec);
+ stream1.read_some(null_buffers(), ec);
+
+ stream1.async_read_some(buffer(mutable_char_buffer), &read_some_handler);
+ stream1.async_read_some(mutable_buffers, &read_some_handler);
+ stream1.async_read_some(null_buffers(), &read_some_handler);
+ int i7 = stream1.async_read_some(buffer(mutable_char_buffer), lazy);
+ (void)i7;
+ int i8 = stream1.async_read_some(mutable_buffers, lazy);
+ (void)i8;
+ int i9 = stream1.async_read_some(null_buffers(), lazy);
+ (void)i9;
+ }
+ catch (std::exception&)
+ {
+ }
+}
+
 void test_sync_operations()
 {
   using namespace std; // For memcmp.
@@ -239,6 +347,7 @@
 BOOST_ASIO_TEST_SUITE
 (
   "buffered_write_stream",
+ BOOST_ASIO_TEST_CASE(test_compile)
   BOOST_ASIO_TEST_CASE(test_sync_operations)
   BOOST_ASIO_TEST_CASE(test_async_operations)
 )


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk