I'm trying to implement an AsyncReadStream stream to read from std::cin and so far have the following code:
template <class MutableBufferSequence, class ReadHandler>
void async_read_some(const MutableBufferSequence &buf, ReadHandler handler) {
char c[1024] = {};
std::streamsize num = std::cin.readsome(c, 1023);
c[num] = 0;
boost::asio::streambuf buff(1023);
std::ostream os(&buff);
os << c;
// How do I get the buff into the buf???? I've tried below:
//boost::asio::buffered_stream<boost::asio::streambuf> buff_stream(buff);
//boost::asio::read(buff_stream, buf);
handler(boost::system::error_code(), boost::asio::buffer_size(buf));
}
I'm aware that some of the code in the above is blocking, when it shouldn't really be but that's besides my problem here (I think). I've checked the documentation for MutableBufferSequence http://www.boost.org/doc/libs/1_41_0/doc/html/boost_asio/reference/MutableBufferSequence.html and there doesn't seem any obvious way to do this. Obviously I'm drastically misunderstanding something.