LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-10-2009, 07:01 AM   #1
wagmare
Member
 
Registered: Jan 2009
Posts: 62

Rep: Reputation: 15
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 ...
 
Old 06-10-2009, 08:05 AM   #2
wje_lq
Member
 
Registered: Sep 2007
Location: Mariposa
Distribution: FreeBSD,Debian wheezy
Posts: 811

Rep: Reputation: 179Reputation: 179
Quote:
Originally Posted by wagmare View Post
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?
 
Old 06-10-2009, 09:03 AM   #3
fantas
Member
 
Registered: Jun 2007
Location: Bavaria
Distribution: slackware, xubuntu
Posts: 143

Rep: Reputation: 22
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 ?
 
Old 06-10-2009, 04:20 PM   #4
wje_lq
Member
 
Registered: Sep 2007
Location: Mariposa
Distribution: FreeBSD,Debian wheezy
Posts: 811

Rep: Reputation: 179Reputation: 179
Quote:
Originally Posted by fantas View Post
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 View Post
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.
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
unix socket programming wagmare Linux - Networking 4 06-10-2009 11:53 PM
problem in unix socket programming wagmare Linux - Networking 0 06-05-2009 05:53 AM
Is it anyway we can use C Socket programming (In unix) in Windows? haxpor Programming 3 07-24-2007 05:01 AM
unix/socket programming, which book should i read first ??? b0nd Linux - General 2 05-06-2006 12:47 AM
Unix socket programming - how to sent a file Scrag Programming 9 03-28-2004 09:54 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:20 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration