Boost logo

Boost Users :

Subject: Re: [Boost-users] ASIO async I/O with iostream?
From: Jay Sprenkle (jsprenkle_at_[hidden])
Date: 2009-12-09 15:45:20


On Wed, Dec 9, 2009 at 1:18 PM, Igor R <boost.lists_at_[hidden]> wrote:

> > I'd like to be able to skip the buffer and just read directly to the
> stream
> > with an event to notify me of the arrival of data.
>
> You can use asio::streambuf. It inherits std::streambuf, and you can
> use it with istream and ostream, just as you do with standard
> streambufs. But note that any buffer must outlive the async.operation.
>
>
I found an example (below) but it seems to be pretty much the same as my
current code to write to a character array and copy the buffer into the
stream. It also looks like it might choke if the read was larger than 512
bytes. Thanks for the suggestion anyway though.

boost::asio::streambuf b;

// reserve 512 bytes in output sequence
boost::asio::streambuf::const_buffers_type bufs = b.prepare(512);

size_t n = sock.receive(bufs);

// received data is "committed" from output sequence to input sequence
b.commit(n);



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