Boost logo

Boost Users :

Subject: Re: [Boost-users] [Asio] Making custom std::streambuf for async_read
From: Gavin Lambert (gavinl_at_[hidden])
Date: 2016-08-09 19:50:08


On 9/08/2016 17:13, knarks_at_[hidden] wrote:
> At the moment I'm using async_read with boost::asio::streambuf and this
> works fine but I need a custom stream where every invoke to async_read
> appends the data to my stream.

Asio streambuf already does this, so I'm not sure why you'd want to make
a custom one on that basis.

> The stream should be based on std::streambuf because I want to keep
> the asio interface hidden to the user.

While I understand the motivation, note that some of the performance of
Asio relies on the compiler being able to inline things. There's
certainly nothing stopping you from hiding it but you'll lose some of
the benefits this way. Some of the special features such as strands and
custom allocators also rely on the way that the templates interact.

And Asio's streambuf is already based on std::streambuf; to make a
custom one you'd end up completely duplicating it anyway.

> My first idea was to search for the problem and I ended up with reading
> about MutableBufferSequence but I don't know if this is the right way
> and how to implement this in my streambuf object. Any help is higly
> appreciated.

Asio does support using many other data sequences as buffers, so you can
just use something else other than streambuf if you wish to.

http://www.boost.org/doc/libs/1_61_0/doc/html/boost_asio/overview/core/buffers.html


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