home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / sys / hp / 10101 < prev    next >
Encoding:
Internet Message Format  |  1992-09-07  |  1.9 KB

  1. Xref: sparky comp.sys.hp:10101 comp.unix.programmer:4546
  2. Newsgroups: comp.sys.hp,comp.unix.programmer
  3. Path: sparky!uunet!zaphod.mps.ohio-state.edu!wupost!spool.mu.edu!yale.edu!ira.uka.de!rz.uni-karlsruhe.de!rz.uni-karlsruhe.de!chris
  4. From: chris@rz.uni-karlsruhe.de (Christian Finger)
  5. Subject: Re: Sockets, timeouts, and HPUX
  6. Message-ID: <1992Sep5.182349.12673@rz.uni-karlsruhe.de>
  7. Sender: usenet@rz.uni-karlsruhe.de (USENET News System)
  8. Reply-To: finger@rz.uni-karlsruhe.de
  9. Organization: Computer Center, University of Karlsruhe, Germany
  10. References:  <Bu2HJ5.KHA@spock.dis.cccd.edu>
  11. Date: Sat, 5 Sep 1992 18:23:49 GMT
  12. Lines: 43
  13.  
  14. In article <Bu2HJ5.KHA@spock.dis.cccd.edu>, markb@spock.dis.cccd.edu (Mark Bixby) writes:
  15. | I'm running HPUX 8.02 on a 9000/817.  I'm writing a sockets client that talks to
  16. | a remote server machine.  If the server machine is down, the client's
  17. | connect(2) call takes 75 seconds to time out.  Is there any way to change this
  18. | timeout duration, especially to reduce it to something more reasonable like
  19. | 15 seconds?
  20. [ comments about HP's manuals and implementation deleted ]
  21.  
  22. There's a very easy way: connect() can be interrupted by an alarm signal.
  23. Here an example:
  24.  
  25. /* define dummy function somewhere in your source */
  26.  
  27. dummy() {}
  28.  
  29. /* the code that connects to the other host */
  30.  
  31. signal(SIGALRM,dummy);
  32. alarm(timeout);
  33.  
  34. if (connect (sock, (char *) &sin, sizeof (sin)) < 0) {
  35.     if (errno == EINTR) {
  36.         /* timeout reached */
  37.     }
  38.     else {
  39.         /* any other error */
  40.     }
  41. }
  42.  
  43. /* deactivate time bomb */
  44.  
  45. alarm(0);
  46. signal(SIGALRM,SIG_DFL);
  47.  
  48. Hope that helps,
  49.     Christian
  50. -- 
  51.   .     Christian Finger         |  Tel   : (+49) 721/608-4038
  52.  |||    Computer Center          |  Fax   : (+49) 721/32550
  53. \|||    University of Karlsruhe  |  EMail : finger@rz.uni-karlsruhe.de
  54.     /   Postfach 6980            |  X.400 : S = finger; OU = rz
  55.         D-7500 Karlsruhe 1       |          P = uni-karlsruhe; A = dpb; C = de
  56.