home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / lang / perl / 5312 < prev    next >
Encoding:
Text File  |  1992-08-13  |  1.3 KB  |  44 lines

  1. Newsgroups: comp.lang.perl
  2. Path: sparky!uunet!usc!sdd.hp.com!mips!darwin.sura.net!jvnc.net!nuscc!ccechk
  3. From: ccechk@nuscc.nus.sg (Heng Kek)
  4. Subject: Re: help with timeouts
  5. Message-ID: <1992Aug14.065902.4616@nuscc.nus.sg>
  6. Organization: National University of Singapore
  7. References: <1992Aug13.201026.16042@netlabs.com>
  8. Date: Fri, 14 Aug 1992 06:59:02 GMT
  9. Lines: 33
  10.  
  11. Further to what has been discussed on this thread, I'd like to seek
  12. help on the following code fragment.  Basically, I want to set a
  13. timeout on the connect() via alarm() and this is what I came up
  14. with.  It doesn't work because I can't branch (goto) a label in a
  15. subroutine.
  16.  
  17. sub ConnectTo {
  18. ...[stuff omitted]...
  19.   SIG{'ALRM'} = 'Timeout';
  20.   alarm(5);   # set timeout to 5 secs.
  21.   # Call up the server.
  22.   if ($conrc = connect($socket,$addr)) { #May take up to 90 secs
  23.       print "connect ok\n" if $DEBUG ;   #which is much too long.
  24.   }
  25.   LABEL:
  26.   $conrc;       # Report whether connection is successful.
  27. } # end of subroutine
  28.  
  29. sub Timeout {
  30.   goto LABEL if !$conrc;  # Fails to goto LABEL.
  31.   return;
  32. }
  33.  
  34. How do I get the SIGALRM handler to return control to the statement
  35. after the connect() call?
  36.  
  37. Thanks to all respondents.
  38.  
  39. Heng Kek
  40. National University of S'pore
  41. This is perl, version 4.0
  42. $RCSfile: perl.c,v $$Revision: 4.0.1.6 $$Date: 91/11/11 16:38:45 $
  43. Patch level: 19
  44.