Boost logo

Boost Users :

Subject: Re: [Boost-users] [Asio] Making custom std::streambuf for async_read
From: knarks_at_[hidden]
Date: 2016-08-10 15:16:05


Thank you for the response so far. My idea is to prevent unnecessary
copy operations when receiving large files with tcp. For this reason I
thought about implementing my own stream, which writes direct to file or
memory, depending on the situation.

I know that I can connect std::iostream to the asio streambuf but what
about moving the received memory to a std::ofstream or std::stringstream
without having the data twice in memory. Is that possible?

Maybe I'm concerned too much about that problem and a simple copy
operation to the std stream works in most cases.

> 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 mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users


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