gpt4 book ai didi

c++ - boost iostreams : How to create buffered (for reading) TCP stream?

转载 作者:IT老高 更新时间:2023-10-28 22:15:29 24 4
gpt4 key购买 nike

所以我的主要问题是如何在 asio tcp::socket 或 tcp::iostream 之上实现一个结构来实现 some kind of input-seekable filter enter image description here

缓冲区最多 1kb?

最佳答案

我认为像“转到流的末尾”这样的东西对于 TCP 连接是不可能的。像这样的调用(参见下面的代码)是否应该等待(阻塞)连接关闭?当响应达到缓冲区大小(例如 1Kb)时,它应该如何存储响应?

s.seekg (0, ios::end);

因此,通常很难(/不可能?)实现可搜索的 TCP 流。即使您有无限的缓冲区(不仅仅是 1Kb)。

当设置 Content-Length header 时,应该可以为 HTTP(S) 等特定协议(protocol)实现类似 input-seekable 的功能。但在这种情况下,除非您使用 HTTP/1.1 Range header ,否则 1Kb 的固定大小缓冲区将不起作用。

也许有帮助:Christopher M. Kohlhoff(Boost asio 的作者)实现了 Urdl (在 SourceForge 上标记为“Prealpha”)他将 HTTP 连接建模为 istream。我认为 read_some 方法对您来说可能很有趣:https://github.com/jnorthrup/urdl/blob/master/include/urdl/detail/http_read_stream.hpp#L426

关于c++ - boost iostreams : How to create buffered (for reading) TCP stream?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9228796/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com