Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r54467 - trunk/boost/asio
From: chris_at_[hidden]
Date: 2009-06-28 09:20:18


Author: chris_kohlhoff
Date: 2009-06-28 09:20:17 EDT (Sun, 28 Jun 2009)
New Revision: 54467
URL: http://svn.boost.org/trac/boost/changeset/54467

Log:
Treat 0-byte reads and writes as no-ops to comply with the documented type
requirements for SyncReadStream, AsyncReadStream, SyncWriteStream and
AsyncWriteStream.

Text files modified:
   trunk/boost/asio/buffered_read_stream.hpp | 43 +++++++++++++++++++++++++++++++++++++++
   trunk/boost/asio/buffered_write_stream.hpp | 43 +++++++++++++++++++++++++++++++++++++++
   2 files changed, 84 insertions(+), 2 deletions(-)

Modified: trunk/boost/asio/buffered_read_stream.hpp
==============================================================================
--- trunk/boost/asio/buffered_read_stream.hpp (original)
+++ trunk/boost/asio/buffered_read_stream.hpp 2009-06-28 09:20:17 EDT (Sun, 28 Jun 2009)
@@ -230,8 +230,21 @@
   template <typename MutableBufferSequence>
   std::size_t read_some(const MutableBufferSequence& buffers)
   {
+ typename MutableBufferSequence::const_iterator iter = buffers.begin();
+ typename MutableBufferSequence::const_iterator end = buffers.end();
+ size_t total_buffer_size = 0;
+ for (; iter != end; ++iter)
+ {
+ boost::asio::mutable_buffer buffer(*iter);
+ total_buffer_size += boost::asio::buffer_size(buffer);
+ }
+
+ if (total_buffer_size == 0)
+ return 0;
+
     if (storage_.empty())
       fill();
+
     return copy(buffers);
   }
 
@@ -242,8 +255,22 @@
       boost::system::error_code& ec)
   {
     ec = boost::system::error_code();
+
+ typename MutableBufferSequence::const_iterator iter = buffers.begin();
+ typename MutableBufferSequence::const_iterator end = buffers.end();
+ size_t total_buffer_size = 0;
+ for (; iter != end; ++iter)
+ {
+ boost::asio::mutable_buffer buffer(*iter);
+ total_buffer_size += boost::asio::buffer_size(buffer);
+ }
+
+ if (total_buffer_size == 0)
+ return 0;
+
     if (storage_.empty() && !fill(ec))
       return 0;
+
     return copy(buffers);
   }
 
@@ -306,7 +333,21 @@
   void async_read_some(const MutableBufferSequence& buffers,
       ReadHandler handler)
   {
- if (storage_.empty())
+ typename MutableBufferSequence::const_iterator iter = buffers.begin();
+ typename MutableBufferSequence::const_iterator end = buffers.end();
+ size_t total_buffer_size = 0;
+ for (; iter != end; ++iter)
+ {
+ boost::asio::mutable_buffer buffer(*iter);
+ total_buffer_size += boost::asio::buffer_size(buffer);
+ }
+
+ if (total_buffer_size == 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));

Modified: trunk/boost/asio/buffered_write_stream.hpp
==============================================================================
--- trunk/boost/asio/buffered_write_stream.hpp (original)
+++ trunk/boost/asio/buffered_write_stream.hpp 2009-06-28 09:20:17 EDT (Sun, 28 Jun 2009)
@@ -187,8 +187,21 @@
   template <typename ConstBufferSequence>
   std::size_t write_some(const ConstBufferSequence& buffers)
   {
+ typename ConstBufferSequence::const_iterator iter = buffers.begin();
+ typename ConstBufferSequence::const_iterator end = buffers.end();
+ size_t total_buffer_size = 0;
+ for (; iter != end; ++iter)
+ {
+ boost::asio::const_buffer buffer(*iter);
+ total_buffer_size += boost::asio::buffer_size(buffer);
+ }
+
+ if (total_buffer_size == 0)
+ return 0;
+
     if (storage_.size() == storage_.capacity())
       flush();
+
     return copy(buffers);
   }
 
@@ -199,8 +212,22 @@
       boost::system::error_code& ec)
   {
     ec = boost::system::error_code();
+
+ typename ConstBufferSequence::const_iterator iter = buffers.begin();
+ typename ConstBufferSequence::const_iterator end = buffers.end();
+ size_t total_buffer_size = 0;
+ for (; iter != end; ++iter)
+ {
+ boost::asio::const_buffer buffer(*iter);
+ total_buffer_size += boost::asio::buffer_size(buffer);
+ }
+
+ if (total_buffer_size == 0)
+ return 0;
+
     if (storage_.size() == storage_.capacity() && !flush(ec))
       return 0;
+
     return copy(buffers);
   }
 
@@ -264,7 +291,21 @@
   void async_write_some(const ConstBufferSequence& buffers,
       WriteHandler handler)
   {
- if (storage_.size() == storage_.capacity())
+ typename ConstBufferSequence::const_iterator iter = buffers.begin();
+ typename ConstBufferSequence::const_iterator end = buffers.end();
+ size_t total_buffer_size = 0;
+ for (; iter != end; ++iter)
+ {
+ boost::asio::const_buffer buffer(*iter);
+ total_buffer_size += boost::asio::buffer_size(buffer);
+ }
+
+ if (total_buffer_size == 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));


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