mercredi 12 juillet 2017

boost::asio::async_write with forward traversal iterator

I have a forward iterator which generates/handles bytes on-the-fly and would like to use use it to send data with boost::asio::async_write.

In fact, what I have is some custom developed iterator using Boost.Iterator library which has the Forward Traversal Iterator category. This iterator is used to generate some bytes and generate the SHA256 on-the-fly. Is there any way to send these bytes using boost::asio::async_write without the need to copy them into some buffer?

The code looks like that:

sha256hasher hasher;
auto on_the_fly_range = some_range_ctor|boost::adaptors::transformed(std::ref(hasher));

boost::asio::async_write(socket_, on_the_fly_range, [](auto const& ec, auto size){});

Don't worry, that hasher might go out of scope, in my case it'll not, this is just the simplified view. I am only interested, how to make async_write accepting on_the_fly_range. It is very well copyable and will maintain the state.

I understand, that I can introduce a for loop, iterate through the on_the_fly_range create chunks of data and send them, but is there a way to do that without intermediate data prefetch?

Aucun commentaire:

Enregistrer un commentaire