recvfrom max buffer TCP/IP
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.
精彩评论