Re: How full is a UDP socket buffer
From: moi (avk_at_localhost)
Date: 01/24/05
- Next message: moi: "Re: reliable way for obtaining wordsize for preprocessor"
- Previous message: Bjorn Reese: "Re: reliable way for obtaining wordsize for preprocessor"
- In reply to: Anant Padmanath Mudambi: "Re: How full is a UDP socket buffer"
- Next in thread: Sean Burke: "Re: How full is a UDP socket buffer"
- Reply: Sean Burke: "Re: How full is a UDP socket buffer"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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
- Next message: moi: "Re: reliable way for obtaining wordsize for preprocessor"
- Previous message: Bjorn Reese: "Re: reliable way for obtaining wordsize for preprocessor"
- In reply to: Anant Padmanath Mudambi: "Re: How full is a UDP socket buffer"
- Next in thread: Sean Burke: "Re: How full is a UDP socket buffer"
- Reply: Sean Burke: "Re: How full is a UDP socket buffer"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|