简体   繁体   中英

what size of the buffer is sufficient for UDP case of recvfrom?

I'm using recvfrom to receive udp multicast data. As far as I know it receives not more than 1 datagram in call (is that correct?). What buffer size would be enough for such call then? I guess it should be ~MTU of UDP for this machine, but how can I know it on runtime?

I don't want to "overestimate" size of the buffer because I actually have ring-buffers of buffers under the scene and I don't want to spent too much extra memory.

The maximum size of an UDP datagram is 64k. Unless you're allocating a lot of buffers, just use this size.

The maximum size of an IPv4 UDP datagram payload is 65507 bytes, but you won't be getting them other than via the loopback. The best you can do across a real network is the MTU minus 28. The generally accepted practical limit without fragmentation is 534 bytes.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM