LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   unix socket programming (https://www.linuxquestions.org/questions/programming-9/unix-socket-programming-731905/)

wagmare 06-10-2009 07:01 AM

unix socket programming
 
hi friends,
is there any way to find the recv() side socket descriptor that its peer is closed at the other side ..
server will keep sending and client will receives it ... if client process closed i can get errno :EPIPE
but if the server process closed .. recv() in client will receive just value '0' and return sucess ....

is there any other way to find the recv socket property to tell the user that peer process is closed on the other side ...

i try poll() checking POLLRDHUP but in vain ... is there any other way left to find ...

because i want to show the user that the peer process is closed at the other side in recv() on client.c

please help me ... :cry:

wje_lq 06-10-2009 08:05 AM

Quote:

Originally Posted by wagmare (Post 3569070)
but if the server process closed .. recv() in client will receive just value '0' and return sucess ....

is there any other way to find the recv socket property to tell the user that peer process is closed on the other side ...

Returning a function value of 0 is recv()'s way of showing you that the socket is closed on the other side. Unless you're doing non-blocking I/O, that's the normal way to show this.

But you want some other way to show this.

What's wrong with that way?

fantas 06-10-2009 09:03 AM

I believe the return value is only 0 if the connection closes in a correct way, but if it was closed incorrectly you won't get any notification in such a way.

Did you try 'select' an the socket descriptor and observing its return value ?

wje_lq 06-10-2009 04:20 PM

Quote:

Originally Posted by fantas (Post 3569194)
I believe the return value is only 0 if the connection closes in a correct way, but if it was closed incorrectly you won't get any notification in such a way.

If there was an error, you'll get -1 as a return value, and you can check errno for something more specific.
Quote:

Originally Posted by fantas (Post 3569194)
Did you try 'select' an the socket descriptor and observing its return value ?

In case of error, either with reading or writing, select() will tell you that it's possible to read. Then, when you do the read, you'll get the -1, and you can check errno.


All times are GMT -5. The time now is 10:15 AM.