Changeset 54467


Ignore:
Timestamp:
Jun 28, 2009, 1:20:17 PM (9 years ago)
Author:
chris_kohlhoff
Message:

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

Location:
trunk/boost/asio
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/boost/asio/buffered_read_stream.hpp

    r48535 r54467  
    231231  std::size_t read_some(const MutableBufferSequence& buffers)
    232232  {
     233    typename MutableBufferSequence::const_iterator iter = buffers.begin();
     234    typename MutableBufferSequence::const_iterator end = buffers.end();
     235    size_t total_buffer_size = 0;
     236    for (; iter != end; ++iter)
     237    {
     238      boost::asio::mutable_buffer buffer(*iter);
     239      total_buffer_size += boost::asio::buffer_size(buffer);
     240    }
     241
     242    if (total_buffer_size == 0)
     243      return 0;
     244
    233245    if (storage_.empty())
    234246      fill();
     247
    235248    return copy(buffers);
    236249  }
     
    243256  {
    244257    ec = boost::system::error_code();
     258
     259    typename MutableBufferSequence::const_iterator iter = buffers.begin();
     260    typename MutableBufferSequence::const_iterator end = buffers.end();
     261    size_t total_buffer_size = 0;
     262    for (; iter != end; ++iter)
     263    {
     264      boost::asio::mutable_buffer buffer(*iter);
     265      total_buffer_size += boost::asio::buffer_size(buffer);
     266    }
     267
     268    if (total_buffer_size == 0)
     269      return 0;
     270
    245271    if (storage_.empty() && !fill(ec))
    246272      return 0;
     273
    247274    return copy(buffers);
    248275  }
     
    307334      ReadHandler handler)
    308335  {
    309     if (storage_.empty())
     336    typename MutableBufferSequence::const_iterator iter = buffers.begin();
     337    typename MutableBufferSequence::const_iterator end = buffers.end();
     338    size_t total_buffer_size = 0;
     339    for (; iter != end; ++iter)
     340    {
     341      boost::asio::mutable_buffer buffer(*iter);
     342      total_buffer_size += boost::asio::buffer_size(buffer);
     343    }
     344
     345    if (total_buffer_size == 0)
     346    {
     347      get_io_service().post(detail::bind_handler(
     348            handler, boost::system::error_code(), 0));
     349    }
     350    else if (storage_.empty())
    310351    {
    311352      async_fill(read_some_handler<MutableBufferSequence, ReadHandler>(
  • trunk/boost/asio/buffered_write_stream.hpp

    r48535 r54467  
    188188  std::size_t write_some(const ConstBufferSequence& buffers)
    189189  {
     190    typename ConstBufferSequence::const_iterator iter = buffers.begin();
     191    typename ConstBufferSequence::const_iterator end = buffers.end();
     192    size_t total_buffer_size = 0;
     193    for (; iter != end; ++iter)
     194    {
     195      boost::asio::const_buffer buffer(*iter);
     196      total_buffer_size += boost::asio::buffer_size(buffer);
     197    }
     198
     199    if (total_buffer_size == 0)
     200      return 0;
     201
    190202    if (storage_.size() == storage_.capacity())
    191203      flush();
     204
    192205    return copy(buffers);
    193206  }
     
    200213  {
    201214    ec = boost::system::error_code();
     215
     216    typename ConstBufferSequence::const_iterator iter = buffers.begin();
     217    typename ConstBufferSequence::const_iterator end = buffers.end();
     218    size_t total_buffer_size = 0;
     219    for (; iter != end; ++iter)
     220    {
     221      boost::asio::const_buffer buffer(*iter);
     222      total_buffer_size += boost::asio::buffer_size(buffer);
     223    }
     224
     225    if (total_buffer_size == 0)
     226      return 0;
     227
    202228    if (storage_.size() == storage_.capacity() && !flush(ec))
    203229      return 0;
     230
    204231    return copy(buffers);
    205232  }
     
    265292      WriteHandler handler)
    266293  {
    267     if (storage_.size() == storage_.capacity())
     294    typename ConstBufferSequence::const_iterator iter = buffers.begin();
     295    typename ConstBufferSequence::const_iterator end = buffers.end();
     296    size_t total_buffer_size = 0;
     297    for (; iter != end; ++iter)
     298    {
     299      boost::asio::const_buffer buffer(*iter);
     300      total_buffer_size += boost::asio::buffer_size(buffer);
     301    }
     302
     303    if (total_buffer_size == 0)
     304    {
     305      get_io_service().post(detail::bind_handler(
     306            handler, boost::system::error_code(), 0));
     307    }
     308    else if (storage_.size() == storage_.capacity())
    268309    {
    269310      async_flush(write_some_handler<ConstBufferSequence, WriteHandler>(
Note: See TracChangeset for help on using the changeset viewer.