UNIX Socket FAQ

A forum for questions and answers about network programming on Linux and all other Unix-like systems

You are not logged in.

#1 2002-10-04 10:50 PM

Bina
Guest

Re: "Empyting" a socket

I am using Unix domain datagram sockets for IPC. I need to be able to empty all the data waiting to be read from the socket.  Is there any way of doing this short of reopening the socket?
Thanks,
Bina

#2 2002-10-05 12:58 AM

HectorLasso
Administrator
From: Colombia
Registered: 2002-06-12
Posts: 353

Re: "Empyting" a socket

Yes.

To "flush" these sockets, you just put the socket in NON_BLOCKING mode, and then recv() them to a temporary buffer until you get a EWOULDBLOCK.

I guess it works...

Offline

#3 2002-10-05 07:29 AM

Uzume
Administrator
Registered: 2002-08-30
Posts: 186

Re: "Empyting" a socket

Yes. You can read()/recv() it out until there isn't any more as Loco mentions. Not sure nonblocking sockets is required but that is at least one good way. You could also perhaps use a call that tests the for the presence of more data like select() or poll().

Offline

Board footer

Powered by FluxBB