|
Boost Users : |
Subject: [Boost-users] [Asio] streambuf exceptions
From: Dylan Klomparens (dylan.klomparens_at_[hidden])
Date: 2010-02-25 11:48:32
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).
But in my test program, this did not happen. Do I need to enable exception
throwing somehow? Or is streambuf working as intended and not supposed to
throw an exception?
Here is my test program:
#include <iostream>
#include <boost/asio.hpp>
using namespace std;
int main()
{
char in[] = "hello";
char out[6] = {0, 0, 0, 0, 0, 0};
boost::asio::streambuf s;
s.sputn(in, sizeof(in));
s.sgetn(out, sizeof(in));
cout << out << endl << s.size() << endl;
s.consume(1000);
return 0;
}
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