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 04-02-2005, 12:34 PM   #1
jwstric2
Member
 
Registered: Jan 2004
Posts: 105

Rep: Reputation: 15
how to find out if a nonblocking socket is closed


Is Socket Closed?

I have investigated this problem shown in the link. Does anyone know of a clean solution to this approach? Im dealing with select and it fall through on a closed socket and reads 0. But according to the select spec just because it falls through and reads 0, it may not indicate an error. Before I even became concerned with dealing with cleaning up sockets I noticed that select sometime fell through with sockets that had no available data.
 
Old 04-02-2005, 09:12 PM   #2
randyding
Member
 
Registered: May 2004
Posts: 552

Rep: Reputation: 31
select() doesn't tell you anything about an fd other than read/write has been detected. If the read fd_set triggers then you call read() on the fd to see if there is really data available or the fd has an error or was closed. The return code of read() is -1 on error, (see errno form more details in this case) and 0 if the remote side closed the connection.
 
Old 04-02-2005, 11:47 PM   #3
jwstric2
Member
 
Registered: Jan 2004
Posts: 105

Original Poster
Rep: Reputation: 15
why does select sometimes randomly fall through when there is no data to read? i've had select fall through and when i read I get 0 bytes even though the other side is still open. maybe someone could help explain that one to me?
 
Old 04-03-2005, 10:14 AM   #4
randyding
Member
 
Registered: May 2004
Posts: 552

Rep: Reputation: 31
Besides timeout, sending a signal to the process causes select to return -1 and errno==EINTR. select must always have a loop around it to account for this and restart the select operation. Without seeing code I can't think of any other reason for this.
 
  


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
how do i know if the connection is closed using a nonblocking socket? Thinking Programming 2 10-06-2005 08:53 AM
how to make nonblocking FILE *fp? Thinking Programming 1 09-14-2005 05:07 AM
nonblocking connect jwstric2 Programming 0 12-30-2004 12:00 PM
tightVNC - RFB socket closed abapdr Linux - General 0 05-26-2004 03:26 AM
setting a socket to nonblocking mode raven Programming 1 06-02-2002 10:56 PM

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

All times are GMT -5. The time now is 01:53 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