[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[MacPerl] Alarm Signal in MacPerl



A while back, Chris Nandor submitted the piece of code below to demonstrate
that alarm works properly on MacPerl.  However, when I try similar things
with networking code, the alarm never kicks in.  Is this a symptom of the
Mac networking capabilities?

What I'm trying to do is set a timeout on a network connection.  I'm
writing a program that will need to regularly check a variety of servers
for information, and if one of the servers gets hung up, I don't want the
client to freeze waiting for a connection.

My code snippet:
alarm 10;
connect(...);
alarm 0;

This code has hung for minutes in bad situations.  An example being that
the server program wasn't responding properly.

Here's the code from Chris Nandor:


#!perl -wl
use CGI qw(:all);
$SIG{ALRM} = \&do_die;
print header('text/plain');
alarm(5);
foreach(0..99){print;sleep(1)}
sub do_die {print "Time's up!";exit}

This returns to me after 5 seconds, instead of 100:

0
1
2
3
4
Time's up!



***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch