简体   繁体   English

哪种缓冲区大小足以满足Recvfrom的UDP情况?

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

I'm using recvfrom to receive udp multicast data. 我正在使用recvfrom来接收udp组播数据。 As far as I know it receives not more than 1 datagram in call (is that correct?). 据我所知,它在呼叫中接收的数据报不超过1个(是吗?)。 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? 我想这应该是这台机器的UDP〜MTU,但是如何在运行时知道它呢?

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. UDP数据报的最大大小为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. IPv4 UDP数据报有效负载的最大大小为65507字节,但是除了通过环回,您将无法获得它们。 The best you can do across a real network is the MTU minus 28. The generally accepted practical limit without fragmentation is 534 bytes. 在实际网络中,您能做的最好的事情就是MTU减28。不带碎片的公认的实际限制是534个字节。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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