Question

I have a system where a single-byte message is sent via a UDP socket from one process to another when something happens. On the receiving end, it matters not if this event has happened once or a dozen or even a million times.

Rather than making many useless recvfrom() calls, I thought maybe I could just use setsockopt to set SO_RCVBUF to 1 which I am hoping would cause the system to simply ignore all but the first message (until it is read thus allowing another). However, googling turns up some evidence that this might not be 100% portable (it looks like some systems might quietly enforce a minimum size?).

So before I go to the work of trying this I was wondering if anyone knew how likely this would be to work? This is on Red Hat Linux if that matters in any way.

Was it helpful?

Solution

On linux, the actual size is bound between SOCK_MIN_RCVBUF and sysctl_rmem_max, but the call to setsockopt will never fail. See here. This includes overhead, among other things, for a struct sk_buff.

The value of SOCK_MIN_RCVBUF is:

#define SOCK_MIN_RCVBUF (2048 + sizeof(struct sk_buff))

As to what you want to do: AFAIK, there is no way to clear the receive buffer without reading (or closing the socket).

OTHER TIPS

You are assuming SO_RCVBUF is measured in bytes of application data. For UDP, it isn't on any platform that I know of.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top