So my main question here is how to implement a structure on top of asio tcp::socket or tcp::iostream that would implement some kind of input-seekable filter
with buffer up to say 1kb
?
I think something like "go to the end of the stream" won't be possible for a TCP connection. Should a call like this (see following code) wait (block) for the connection to close? And how should it store the response when it reaches the buffer size (for example 1Kb)?
s.seekg (0, ios::end);
So it will be hard (/impossible?) to implement a seekable TCP stream in general. Even if you have a unlimited buffer (not only 1Kb).
It should be possible to implement something like input-seekable for specific protocols such as HTTP(S) when the Content-Length header is set. But also in this scenario a fixed size buffer of 1Kb won't work unless you use the HTTP/1.1 Range header.
Perhaps it helps: Christopher M. Kohlhoff (author of Boost asio) implemented Urdl (marked as 'Prealpha' on SourceForge) where he modeled the HTTP connection as a istream. I think the method read_some could be interesting to you: https://github.com/jnorthrup/urdl/blob/master/include/urdl/detail/http_read_stream.hpp#L426
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With