Boost logo

Boost Users :

Subject: Re: [Boost-users] [Asio] streambuf exceptions
From: Igor R (boost.lists_at_[hidden])
Date: 2010-02-25 12:05:51


> I'm using an asio::streambuf to read and write data to a socket. Despite my
> best efforts, I can't get the streambuf to throw an exception if I consume
> too much. I'm trying to get it to throw an exception so I can test an error
> case.
>
> The documentation says streambuf::consume will throw an std::length error if
> the requested amount to read is greater than the input stream size
> (http://www.boost.org/doc/libs/1_42_0/doc/html/boost_asio/reference/basic_streambuf/consume.html).

It's a bug in the ducumentation.
The function is implemented as follows:
  void consume(std::size_t n)
  {
    if (gptr() + n > pptr())
      n = pptr() - gptr();
    gbump(static_cast<int>(n));
  }

So it doesn't throw anything - it just wouldn't allow you to consume
more data than available.
Actually, it seems to be the correct and consistent behavior.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net