Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Boost iostreams: How to create buffered (for reading) TCP stream?

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 enter image description here

with buffer up to say 1kb?

like image 946
myWallJSON Avatar asked Feb 10 '12 13:02

myWallJSON


1 Answers

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

like image 164
Günther Makielski Avatar answered Oct 25 '22 08:10

Günther Makielski