Re: How full is a UDP socket buffer

From: moi (avk_at_localhost)
Date: 01/24/05


Date: Mon, 24 Jan 2005 20:08:24 +0100

Anant Padmanath Mudambi wrote:
> Hi,
> Here is the reason why I need to know how full a UDP socket's
> receive buffer. I have 2 threads, T1 and T2. T1 recv()s packets from a
> UDP socket and puts them in a buffer in memory (call it the application
> buffer). T2 copies data from the application buffer into a file on disk.
> Now I would have liked the T1 thread to not get suspended while T2 is
> doing I/O, but that is not happening. T1 cannot (atleast not always) empty
> the UDP receive buffer while T2 is writing to file. Sometimes this causes
> the UDP buffer to overflow. Is there any way to ensure that T1 can keep
> receiving packets from the UDP socket while T2 is doing I/O?
>
> One solution I thought of was to allow T2 to start the disk write only
> when we know that the UDP receive buffer has enough space to store most
> of the incoming packets until T1 gets a chance to recv() from it. That's
> why I thought I needed to find out how full the UDP socket buffer is.
> Any suggestions?
>
> Thank you,
> Anant.
>

You don't need threads. (especially if you are on a single processor
machine) DS is right: priority#1 is emptying the socket buffer. this
leads to the following pseudo code:

while (1) {
        if (socket readable)
                read it in;
        else
                do something useful;
                /* such as: writing *one* buffer to disk */
        }

This will of course fail if packets come in faster then you can possibly
process, causing your buffers to fill all available program memory.
But that is (in most cases) always better than dropping network packets.

for the socket readable condition you could use select()/poll or put the
socket into non-blocking mode (and preferably both ...)

HTH,
AvK



Relevant Pages

  • Re: Losing UDP packets with MFC Sockets
    ... CPU load is not the main culprit in UDP ... > the input buffer is being overload and packets are being discarded. ...
    (microsoft.public.vc.mfc)
  • Re: UDP server socket
    ... >> whats the maximum number of datagrams that can queue up on a UDP ... or is that system dependent? ... > or duplicated packets yourself. ... size of the buffer and is there any way of increasing it. ...
    (comp.lang.python)
  • Re: UDP packets
    ... Why did you choose UDP in the first place? ... and client run on the same machine. ... 100000 UDP packets within 2 min. ... Even for the same buffer size, ...
    (comp.unix.programmer)
  • Re: How full is a UDP socket buffer
    ... UDP socket and puts them in a buffer in memory (call it the application ... of the incoming packets until T1 gets a chance to recv() from it. ...
    (comp.unix.programmer)
  • Re: UDP packets
    ... and client run on the same machine. ... 100000 UDP packets within 2 min. ... there's no point in having a send buffer. ...
    (comp.unix.programmer)