SPUG: Need an asynchronous alarm handler

Jim Flanagan jimfl at colltech.com
Fri May 25 14:47:45 CDT 2001


--Also Sprache ced at carios2.ca.boeing.com On Friday, May 25, 2001 11:43 AM 
-0700:

     >    > alarm $timeout;
     >    > $foo = eval {
     >    >    local $SIG{ALRM} = sub { die "TIMEOUT" };
     >    >    $socket->accept()
     >         alarm 0; # move alarm call to here
     >    > }
     >    > # alarm 0;   # move alarm call from here
     >
     > Very minor nit but alarm(0) should actually be moved
     > inside the eval. Otherwise, there's a small window for
     > the alarm to go off early as someone pointed out on
     > clpm.

  Unfortunately, this code wants the return value of the eval block, so
  putting the alarm inside the block will break it. So, we'd have to

    eval {
      $SIG{ALRM} = sub { die "TIMEOUT" };
      $foo = $socket->accept;
      alarm(0);
    };

  Another nit with my own code, I forgot a semicolon. It should be

    $foo = eval { ... };

--
Jim Flanagan          Collective Technologies
jimfl at colltech.com   http://www.colltech.com

 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     POST TO: spug-list at pm.org       PROBLEMS: owner-spug-list at pm.org
      Subscriptions; Email to majordomo at pm.org:  ACTION  LIST  EMAIL
  Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
 For daily traffic, use spug-list for LIST ;  for weekly, spug-list-digest
  Seattle Perl Users Group (SPUG) Home Page: http://www.halcyon.com/spug/





More information about the spug-list mailing list