Re: How full is a UDP socket buffer

From: Sean Burke (foobar_at_mystery.org)
Date: 01/24/05


Date: Mon, 24 Jan 2005 20:49:10 GMT


moi <avk@localhost> writes:

> 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 ...)

>From the OP's description, it seems possible that there is only
one memory buffer shared between T1 and T2, causing the threads
to contend for the buffer. If so, then using a queue to connect
T1 and T2 would relieve such contention, and allow bursts of UDP
data to be buffered.

-SEan



Relevant Pages

  • UDP ( TIBCO rvd.exe ) + Windows 2003 ( NDIS 5 AFD.SYS miniport ? ) + Gigabyte (Broadcom) : any know
    ... We encounter an issue with UDP buffer size on a Windows 2003 + gigabyte ... We detect it because we can't use Tibco ...
    (microsoft.public.windows.server.networking)
  • Re: C# Socket Programming
    ... i am a software developer and i need to use .NET 2.0 with C#. ... So i have init a UDP socket like socket with the ... SocketException that say the internal Buffer size is either to small ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: How full is a UDP socket buffer
    ... > UDP socket and puts them in a buffer in memory (call it the application ... > receiving packets from the UDP socket while T2 is doing I/O? ... > of the incoming packets until T1 gets a chance to recvfrom it. ...
    (comp.unix.programmer)
  • 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: Losing UDP packets with MFC Sockets
    ... a call to ReceiveFrom method is done. ... 2.- A CByteArray object is creating with 'new' with data received from buffer. ... class to indicate the packet arrival. ... CPU load is not the main culprit in UDP ...
    (microsoft.public.vc.mfc)