Networking Forums

Networking Forums > Computer Networking > Linux Networking > flushing a socket buffer

Reply
Thread Tools Display Modes

flushing a socket buffer

 
 
soj
Guest
Posts: n/a

 
      03-20-2007, 06:28 AM
Hi friends,

I've a networking application, which is having some pre-configured
memory (region and pool), from which application supposed to allocate
buffer to read data from socket.
The application will not read data from the receive buffer (in kernel)
when it's not able to allocate memory (due to out of resource). This
will cause recieve buffer to overflow as peer is continuously sending
data.

The question is, I'd like to know if we can flush out the receive
buffer without reading into application?. I don't want to read the
"old" data present in the receive buffer ?
Is there any way to do this?

Any suggestions would be greatly appreciated.

Thanks in advance,
-Soj

 
Reply With Quote
 
 
 
 
Rick Jones
Guest
Posts: n/a

 
      03-20-2007, 04:50 PM
soj <(E-Mail Removed)> wrote:
> The question is, I'd like to know if we can flush out the receive
> buffer without reading into application?. I don't want to read the
> "old" data present in the receive buffer ? Is there any way to do
> this?


You could close() the socket and open a new one.

If this is a socket bound to a UDP endpoint, you will have a window
where the remote sender could be triggering ICMP Destination
Unreachable, Port Unreachable (IIRC) messages which may or may not be
sent back to the remote application.

With UDP, unless you can guarantee you will be keeping-up with the
stream, you probably want to implement some sort of application-level
flow control between your end and the remote...

If this is a socket bound to a TCP endpoint (probably not since you
mention overflow, but trying to be complete...), you will have a
window where the remote sender will probably trigger RST segments. Of
course, if this is a TCP endpoint, the TCP flow control likely means
that the remote sender got flow-controlled and there may not be all
that much "new" data in the first place. The remote has to know to
reconnect...

Otherwise, I'm pretty sure that the only (portable at least) thing to
do is just read the data from the socket and not do anything with it.

Now, that new-fangled (perhaps egg-laying-wolly-milk-pig SCTP has,
IIRC a way to specify the timliness of data to SCTP and have it drop
it all on its own... no idea if all the systems involved in what you
want to do include support for SCTP.

rick jones
--
Process shall set you free from the need for rational thought.
these opinions are mine, all mine; HP might not want them anyway...
feel free to post, OR email to rick.jones2 in hp.com but NOT BOTH...
 
Reply With Quote
 
soj
Guest
Posts: n/a

 
      03-21-2007, 03:56 AM
Thanks Rick,

But I still wondering there is no way to just flush out data from the
receive buffer ?
I searched a lot to get ride of this.. but no avail and seems like
socket options are also of no help here..
Here, is my case, I can't read data from socket as I dont have enough
memory to allocate.

Rgds,
-soj

On Mar 20, 10:50 pm, Rick Jones <rick.jon...@hp.com> wrote:
> soj <jul....@gmail.com> wrote:
> > The question is, I'd like to know if we can flush out the receive
> > buffer without reading into application?. I don't want to read the
> > "old" data present in the receive buffer ? Is there any way to do
> > this?

>
> You could close() the socket and open a new one.
>
> If this is a socket bound to a UDP endpoint, you will have a window
> where the remote sender could be triggering ICMP Destination
> Unreachable, Port Unreachable (IIRC) messages which may or may not be
> sent back to the remote application.
>
> With UDP, unless you can guarantee you will be keeping-up with the
> stream, you probably want to implement some sort of application-level
> flow control between your end and the remote...
>
> If this is a socket bound to a TCP endpoint (probably not since you
> mention overflow, but trying to be complete...), you will have a
> window where the remote sender will probably trigger RST segments. Of
> course, if this is a TCP endpoint, the TCP flow control likely means
> that the remote sender got flow-controlled and there may not be all
> that much "new" data in the first place. The remote has to know to
> reconnect...
>
> Otherwise, I'm pretty sure that the only (portable at least) thing to
> do is just read the data from the socket and not do anything with it.
>
> Now, that new-fangled (perhaps egg-laying-wolly-milk-pig SCTP has,
> IIRC a way to specify the timliness of data to SCTP and have it drop
> it all on its own... no idea if all the systems involved in what you
> want to do include support for SCTP.
>
> rick jones
> --
> Process shall set you free from the need for rational thought.
> these opinions are mine, all mine; HP might not want them anyway...
> feel free to post, OR email to rick.jones2 in hp.com but NOT BOTH...



 
Reply With Quote
 
Rick Jones
Guest
Posts: n/a

 
      03-21-2007, 04:53 PM
soj <(E-Mail Removed)> wrote:
> But I still wondering there is no way to just flush out data from
> the receive buffer ? I searched a lot to get ride of this.. but no
> avail and seems like socket options are also of no help here..
> Here, is my case, I can't read data from socket as I dont have
> enough memory to allocate.


Nothing says you cannot just overwrite the same smallish buffer until
you've drained as much as you like. Heck, in _theory_ you could read
into a single-byte buffer over and overagain to do the drain - however
that may take more cycles than normal processing.

It could even be a "buffer" on the stack rather than something
allocated from the heap. Or you allocate a suitably sized "bit bucket
buffer" at initialization on the assumption you will need it later.

rick jones
--
a wide gulf separates "what if" from "if only"
these opinions are mine, all mine; HP might not want them anyway...
feel free to post, OR email to rick.jones2 in hp.com but NOT BOTH...
 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Clear UDP socket kernel buffer. Joe Beanfish Linux Networking 0 08-17-2009 05:31 PM
Monitor UDP socket buffer Frederic Mayot Linux Networking 0 03-16-2007 01:57 PM
How to read all data from kernel buffer for a socket fd (which uses TCP ) will_u_tellmemore Linux Networking 0 12-21-2006 01:23 PM
How big is socket receive buffer, and how to control it? C. J. Clegg Linux Networking 1 04-30-2006 08:58 AM
socket buffer size Pirabhu Raman Linux Networking 1 08-18-2004 09:48 PM



1 2 3 4 5 6 7 8 9 10 11