ioctl to determine if socket is closed in C?

ioctl to determine if socket is closed in C?

Post by Mike Dorm » Wed, 17 Dec 1997 04:00:00



Does anyone know of an appropriate ioctl call I could make to determine if
a socket connection has been closed or not (i.e. get the connection
"status")?  I've searched and searched for ioctl documentation on the web,
but I'm unable to find much of anything.  Any ideas?

thanks!
mike

--

Webmaster - Washington High School - http://www.crwash.k12.ia.us/

 
 
 

ioctl to determine if socket is closed in C?

Post by Bjorn Ree » Thu, 18 Dec 1997 04:00:00



> Does anyone know of an appropriate ioctl call I could make to determine if
> a socket connection has been closed or not (i.e. get the connection
> "status")?  I've searched and searched for ioctl documentation on the web,
> but I'm unable to find much of anything.  Any ideas?

There is no such thing. For further info see

  http://kipper.york.ac.uk/~vic/sock-faq/

 
 
 

ioctl to determine if socket is closed in C?

Post by thirdrc » Fri, 19 Dec 1997 04:00:00



> Does anyone know of an appropriate ioctl call I could make to determine if
> a socket connection has been closed or not (i.e. get the connection
> "status")?  I've searched and searched for ioctl documentation on the web,
> but I'm unable to find much of anything.  Any ideas?

> thanks!
> mike

If the socket were open a read of zero bytes would instantly return
zero. But if the socket were closed the same would result in error
(EBADF).

Jeff

(ommit the '2' to reply)

 
 
 

1. : How to determine if a (TCP) socket has closed without reading

Hi,

I need to be able to consistently determine when the remote side of a TCP
socket has closed.

I know that if you read eof from the socket that often means it has closed,
but if you don't get eof, then you have to consume data.  I could live with
that, but when the socket is set to nonblocking, receiving eof is ambiguous.  
It could just mean that there was no data immediately available.

SIGPIPE might occur when attempting to read from a closed socket (is this
consistent?), but again there is the problem of potentially consuming data.

I wanted to find some way of polling for or of being notified when TCP sockets
close.  For example, in System V's TLI interface, you can call t_rcvdis to
receive notification of a closed connection.

My program uses select to handle a list of sockets with a single process and
puts the sockets in nonblocking mode, so as a workaround, I decided to set the
highwater mark less than the lowwater mark so I could get a list of only
closed sockets and sockets with errors from select.  I'm only afraid that this
could cause some unexpected behavior in other processes or kernel processes if
my program is interrupted while the buffer size indicators are set that way.

Does anyone know of any specific problems that could be caused?
Also, does anyone know of a cleaner, better (more portable) way to acheive
this?

I'm using Linux kernel v.2.0.36 from Debian 2.1, but I'd like to make my code
as portable as possible.

Thanks in advance!

Waleed

2. cannot PING itself

3. Determining when a remote socket has been closed

4. Preferred backup?

5. shutdown(s, 2) vs close(s) for closing unix domain sockets

6. User's group in PB County

7. Sockets: close() does not close!?

8. Which Monitor with Stealth 64 Video VRAM

9. Closing sockets and closing connections

10. socket close doesn't really close

11. determine throughput from LAN to Internet, Durchsatz vom LAN ins Internet berechnen

12. Reclaiming used socket fd or how to close sockets properly

13. help: close(socket) leaves socket bound ?