从最大缓冲区 TCP/IP 接收
我正在编写一个小型 C 程序来理解套接字。从recvfrom返回的数据的最大长度是多少?
recvfrom(raw, packet_buffer, buf_size, ... );
Linux 中最大的 buf_size 是多少?有没有一个与这个size_t相关的常量?
谢谢
I am writing a small C program to understand sockets. What is the maximum length of data returned from recvfrom?
recvfrom(raw, packet_buffer, buf_size, ... );
what is the maximum buf_size in linux. Is there a constant related to this size_t?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这并不是一个真正的直接答案……有点间接地回答了这个问题。对于 TCP/IP,即使您确定系统上的最大大小是多少,最好实现代码时不依赖于此。使用面向流的套接字,多余的数据不会丢失。因此您可以再次调用接收函数来检索剩余的数据。但对于面向消息的 (UDP) 连接而言,情况并非如此。
This isn't really a direct answer ... somewhat oblique to the question. For TCP/IP, even if you determine what the maximum size is on your system, it would probably be best to implement the code to not rely on that. With stream-oriented sockets, the excess data is not lost. So you can call the receive function again to retrieve the remaining data. That is not true with message-oriented (UDP) connections, though.
我认为最大值是 65535 字节。它不依赖于 MTU,因为它由协议栈本身处理。所以基本上你对网络上发送的有效数据包有一个很好的抽象。
选择 2^16 应该如此,因为它是 TCP 窗口的最大大小(通常它不是 64kb,而是更小):因此它是协议允许 TCP 连接的最大缓冲区。
I think that max is
65535
bytes. It does not depend upon MTU since it's handled by protocol stack by itself.. so basically you have a good abstraction prom the effective packets that are sent on network.The choice of 2^16 should be so because it's the max size of the TCP window (usually it's not 64kb anyway, but smaller): so it's the maximum buffer the protocol allows for a TCP connection.