It's my bad or a bug in boost::asio::streambuf implementation? In down case i create instance of boost::asio::streambuf, then instance of std::istream and write 3 int to streambuf. Then i need read int's from streambuf while it contain a data.
I'm not understand why is.eof() always return false in this code.
I wrote next case:
void TestCase()
{
boost::asio::streambuf sbuf;
try {
std::istream is(&sbuf);
// put three raw ints in streambuf
for( int i=0; i<3; i++ ) {
auto sz = boost::asio::buffer_copy(
sbuf.prepare(sizeof(int)),
boost::asio::buffer(&i, sizeof(int))
);
sbuf.commit(sz);
}
// read from streambuf while not end-of-stream occured
// (not work! why? what wrong?)
while( !is.eof() ) {
int t;
auto sz = is.readsome( reinterpret_cast<char*>(&t), sizeof(int) );
// this work, but why is.eof() not detect end of stream condition
// on next iteration if this condition are commented?
// ( wrong value of t are correct in this example )
#if 1
if( sz < sizeof(int) )
break;
#endif
std::cout << t << ' ';
}
}
catch(std::exception& e) {
std::cout << e.what() << std::endl;
}
}