To minimize latency (I don't care about packet loss) I want the smallest possible receive buffer for UDP. However, when I set SO_RCVBUF to below 1000 (with setsockopt), my program never receives any packets. The datagrams I am sending have 28 bytes of data, for a total on-wire packet size of 70 bytes, so why can I not receive anything if SO_RCVBUF is < 1000? And how do I change this, to allow a smaller buffer size?
Additionally, is it possible to set the buffer in terms of number of packets, rather than bytes? Or is there some way I can manually empty it?
Making the socket receive buffer smaller will not reduce latency.
Instead you need to dequeue all available packets each time. This can be accomplished with a non-blocking socket and edge-triggered epoll
or kqueue
- on "readable" event read until you get EWOULDBLOCK
.
As to why you don't get any input with small SO_RCVBUF
value, look here - http://vger.kernel.org/~davem/skb_sk.html, and here - http://lxr.linux.no/#linux+v2.6.37/include/net/sock.h#L621
Hope this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With