Boost logo

Boost Users :

Subject: Re: [Boost-users] [Asio] Making custom std::streambuf for async_read
From: knarks_at_[hidden]
Date: 2016-08-11 14:17:51


> ASIO does provide posix::stream_descriptor and windows::stream_handle,
> which can wrap native file descriptors and handles (resp.) and provide
> async operations on them. Thus you can read from the network into one
> asio streambuf and then pass the same streambuf to the file write
> operation. This is probably as close to zero-copy as you can get.
>
> Though other than scalability and blocking concerns there's not much
> difference between this and just doing a blocking write to a regular
> fstream -- at the point you're hitting disk the cost of copying memory
> is negligible.
>
> For writing direct to memory, you can simply supply the target memory
> as a buffer to the initial read (making sure to keep track of the
> origin and size correctly as data blocks incrementally arrive,
> remembering that short reads are likely). This will quite literally
> be zero-copy (bar any copies that occur inside the network stack); no
> special streams required.

I'm using my library for HTTP handling and receiving HTTP POST requests.
When the transfer is chunked then every call to the complete handler can
append a small bit of the stream to a stringstream or a file with the
standard c++ features. This would be the most portable way than using
stream_descriptor or stream_handle.


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