|
Boost : |
Subject: [boost] [iostreams] cin wrapper
From: Daniel Larimer (dlarimer_at_[hidden])
Date: 2012-07-06 13:09:29
I am attempting to 'wrap' std::cin such that all 'blocking' occurs in a dedicated 'cin' thread. This is required because in a cooperatively scheduled thread, no fiber can call cin and block.
So I went about attempting a boost::iostreams::source:
class cin_source : public boost::iostreams::source {
streamsize read( char* s, streamsize n ) {
if( n == 0 ) return n;
auto r = std::cin.readsome(s,n);
if( r <= 0 ) {
// post read request to another thread.
// cooperatively wait for it to finish...
return n;
}
return r;
}
};
The problem I have is that this code causes read to be called with 'n == 0';
boost::iostreams::stream<cin_source> my_cin;
char buf[100];
my_cin.read( buf, 100 );
It doesn't matter how I attempt to read from the stream, n always equals 0.
What am I doing wrong?
Dan
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk