home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / unix / programm / 4552 < prev    next >
Encoding:
Internet Message Format  |  1992-09-08  |  2.1 KB

  1. Path: sparky!uunet!usc!rpi!batcomputer!munnari.oz.au!metro!otc!balrog!camh
  2. From: camh@nms.otca.oz.au (Cameron Hutchison)
  3. Newsgroups: comp.unix.programmer
  4. Subject: Detecting a broken socket
  5. Keywords: socket, SunOS, keep_alive
  6. Message-ID: <camh.715839302@balrog>
  7. Date: 7 Sep 92 04:15:02 GMT
  8. Sender: news@otc.otca.oz
  9. Lines: 37
  10.  
  11. I have a problem with a socket connection that I cant seem to find a
  12. solution for. I am trying to detect when the remote end of a socket dies.
  13. I am doing all this on Sun 4's running SunOS 4.1.2.
  14.  
  15. The situation is that I have an open socket to a comms server that
  16. occasionally dies. When this happens I would like to close down the
  17. connection and open a new one. However, I cant seem to find any way
  18. of telling when the other end of the socket dies. Normally I would
  19. be able to tell because a write(2) would fail, but in this instance,
  20. I'm only reading from the socket.
  21.  
  22. I have experimented with the keep alive timer option but I cant seem
  23. to get it to work. I set the option correctly with setsockopt(2) (and
  24. have verified that it is set by reading it back with getsockopt(2)).
  25. As I understand it, my select(2) call will return with a read ready
  26. on the broken socket and the read(2) will return 0 bytes. This just
  27. isn't happening. The select does not return.
  28.  
  29. My method of testing the keep alive timer was to have a server
  30. machine "emulating" the comms server (from the standpoint of a socket
  31. connection) and a client machine to connect to it. I then simulated
  32. the dropping of the connection by pulling the network connection
  33. to the server machine. I let the client machine run for about 45
  34. minutes before giving up. The client machine did not detect the
  35. broken connection.
  36.  
  37. Another solution might be to periodically check the socket. However,
  38. I don't know how to check the socket. I don't want to do any reads or
  39. writes (ie the check must be passive) and I could see no other system
  40. calls available that might help.
  41.  
  42. Does anybody have any clues as to what is going on with the keep
  43. alive timer, or failing that, a way to periodically check the socket?
  44.  
  45. --
  46. Cameron Hutchison (camh@nms.otca.oz.au)
  47. Beware of the clams
  48.