读取套接字中的缓冲区

发布于 2024-11-27 01:24:38 字数 87 浏览 2 评论 0原文

如果read()的返回值与缓冲区大小相同,我如何读取其余信息?如果再次调用read,它会读取下一个数据块,还是从头开始读取,或者未读入缓冲区的信息会永久丢失吗?

If the return value of read() is the same as the buffer size, how do I read the rest of the information? If read is invoked again, will it read the next chunk of data, or read from beginning again, or is the information not read into the buffer permanently lost?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

顾冷 2024-12-04 01:24:38

在 TCP (SOCK_STREAM) 套接字上,您可以获得下一个数据块。从 TCP 套接字读取类似于从文件读取。

在 UDP (SOCK_DGRAM) 数据报套接字上,如果缓冲区不足以消耗整个数据报,则会丢失数据报的其余部分。后续读取将消耗下一个到达的数据报。

On a TCP (SOCK_STREAM) socket, you get the next chunk of data. Reading from TCP sockets are analogous to reading from a file.

On a UDP (SOCK_DGRAM) datagram socket, if your buffer isn't sufficient to consume the entire datagram, you lose the rest of the datagram. A subsequent read will consume the next datagram that arrives.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文