SPUG: Need an asynchronous alarm handler
Jim Flanagan
jimfl at colltech.com
Fri May 25 13:47:41 CDT 2001
--Also Sprache "Patterson, David S (Pat)" <davidpa at avaya.com> On Friday,
May 25, 2001 11:13 AM -0700:
> I see that there's an alarm function in the built-in library, but
> how do you setup a callback function to be called when a SIGALARM is
> generated?
>
> Basically, I'm looking for a snippet to show me how to set up async
> alarm handling.
$SIG{ALRM} = sub { print "Alarm went off!\n" };
or
$SIG{ALRM} = \&do_some_stuff;
or, a more complicated example:
alarm $timeout;
$foo = eval {
local $SIG{ALRM} = sub { die "TIMEOUT" };
$socket->accept()
}
alarm 0;
if ($@ =~ /TIMEOUT/) {
print "Timed out\n"
}
while ($foo->getline) {
# do some stuff
}
--
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