Hi, In some cases, I'd like to explicitly discard packets waiting on the socket with as little overhead as possible. It seems there's no explicit "drop udp buffer" system call, but maybe I'm wrong?
The next best way would be probably to recv
the packet to a temporary buffer and just drop it. It seems I can't receive 0 bytes, since man says about recv
: The return value will be 0 when the peer has performed an orderly shutdown.
So 1 is the minimum in this case.
Is there any other way to handle this?
Just in case - this is not a premature optimisation. The only thing this server is doing is forwarding / dispatching the UDP packets in a specific way - although recv
with len=1
won't kill me, I'd rather just discard the whole queue in one go with some more specific function (hopefully lowering the latency).