开发者

recvfrom max buffer TCP/IP

开发者 https://www.devze.com 2022-12-20 16:35 出处:网络
I am writi开发者_Python百科ng a small C program to understand sockets. What is the maximum length of data returned from recvfrom?

I am writi开发者_Python百科ng 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


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号