SO_KEEPALIVE and broken connections

SO_KEEPALIVE and broken connections

Post by Jason Cro » Mon, 12 Jul 1993 04:38:38



My client program processes data locally, but periodically checks for
new data from the server on an established socket connection.  I use
select() for possible timeouts prior to a read(), but select() won't
tell me if the server goes away (ie the AUI cable is yanked).

I attempted to use setsockopt() and the SO_KEEPALIVE option to determine
whether I have a valid socket connection.  Unfortunately I haven't had
much success.  

In my testing, I get a socket descriptor, make a connection to the server,
and then use setsockopt();

   int toggle = 1;

   setsockopt(sockfd,SOL_SOCKET,SO_KEEPALIVE,(char *) &toggle,sizeof(toggle));

(setsockopt() returns a zero.  Also, I tried using setsockopt() prior to
making the connection, but it made no difference).

To test for a broken connection, I physically disconnect the AUI cable
on the server side, and on the client side I process data for a few minutes
and then attempt to read data whereby I timeout properly from using the
select() call.  However, so_error should be set to ETIMEDOUT from using
setsockopt(), but remains set at zero.  Any help would be appreciated.
--
ciao,
jason c.

 
 
 

SO_KEEPALIVE and broken connections

Post by Bjarne Blichfel » Tue, 13 Jul 1993 17:56:41


|> My client program processes data locally, but periodically checks for
|> new data from the server on an established socket connection.  I use
|> select() for possible timeouts prior to a read(), but select() won't
|> tell me if the server goes away (ie the AUI cable is yanked).
|>
[ stuff deleted ]

|>
|> To test for a broken connection, I physically disconnect the AUI cable
|> on the server side, and on the client side I process data for a few minutes
                                                                   ^^^^^^^^^^^^

This might be your problem.
The timers involed in keepalives last for a lot longer than a few minutes.
On the systems I have tested we are talking about 2 - 2,5 Hours !

A very nice description of the invovled timers can be found in :
  The Design and Implementation of the
   4.3 BSD UNIX Operating system
  By. Lefler, McKusick , Karels and Quarterman.

|> and then attempt to read data whereby I timeout properly from using the
|> select() call.  However, so_error should be set to ETIMEDOUT from using
|> setsockopt(), but remains set at zero.  Any help would be appreciated.
|> --
|> ciao,
|> jason c.

Good luck
Bjarne B.

 
 
 

1. SO_KEEPALIVE - How to detect a broken socket connection without read/write?

After reading Andrew's FAQ for this group, I still have a problem unsolved
satisfactorily.  The problem is, for a given TCP/SOCK_STREAM socket (int
sockfd), how can you tell the peer has shutdown the connection?  

I don't want to read because I don't want to be blocked when socket is not
broken (NB. recv(..MSG_PEEK..) may block too - just thought, I should try
nonblocking i/o in this case tomorrow :-)  I don't want to write when I
may not have anything to write about.

Richard Stevens' "Unix Network Programming" and Solairs 2.5 man page said
setsockopt(.. SO_KEELALIVE ..) will force a periodic (Solaris: every
minute) transmission when socket is idle, and if there is no response for
*CERTAIN* length of time (do anyone how long is this?), Richard's book
says so_error of struct socket will be set to ETIMEDOUT, Solaris man page
does not say anything of this kind.  Anyway, I used getsockopt(.. SO_ERROR
.) to read so_error, and btwn Solaris client & server, so_error remains 0
but when I try it btwn WIN32 server and Solaris client, getsockopt will
fail on server shutdown.

Does any one know why?

Thanks in advance

Chuck
--
Actrix Networks Limited                  Internet Service Providers.

2. What this mean with X stuff

3. SO_KEEPALIVE broken under Linux 2.2.x?!

4. Mary had a little grep

5. ftp connection warning: setsockopt (SO_KEEPALIVE): Invalid argument

6. How do you back up a terabyte?

7. auto re-connection of a slip line if connection broken?

8. Qlogic FC card for ESS?

9. Matrox Mystique ands X.

10. Make broken, top broken, flock errors, kernel modules broken

11. 2.5: ieee1394 still broken, vesafb still broken, ipv6 still broken

12. SO_KEEPALIVE socket option?

13. setsockopt and SO_KEEPALIVE