LWP get and timeout
Gildas Perrot (perrot@francenet.fr)
Fri, 19 Jul 1996 11:30:26 +0200
Hi,
I am creating a Perl function which get an URL but I want to set up a timeout
on this function. To do that, I use "alarm" and $SIG{ALRM} value.
However, in the case of my get_url function it doesn't work the fucntion never
times out. However, with waiting fcntion, it works.. Any idea about this
problem ?
Thanks in advance for your help.
Gildas.
#!/usr/bin/perl5
use Getopt::Std;
use LWP;
use Time::HiRes qw(gettimeofday);
$timeout = 120;
$delai = 5;
$count = 1;
$innacessible = 0;
$timed_out = 0;
getopts('d:hn:m:o:t:');
$timeout = $opt_t if (defined($opt_t) );
$url = @ARGV[0];
# how many request do we send
$count = $opt_n if (defined($opt_n) );
# delai entre chaque transfert
$delai = $opt_d if (defined($opt_d));
eval {
local $SIG{ALRM} = sub { die "TIMED OUT" };
alarm $timeout;
&url_get;
#&waiting;
alarm 0;
};
if ($@ =~ /TIMED OUT/) {
$output = "TIMEOUT $timeout s.";
}
elsif ($innacessible == 1) {
$output = "$url INACCESSIBLE";
}
else {
$output= $length*$count/$duration/1024;
}
if (defined($opt_o)) {
open(SORTIE,">>$opt_o") || die "Impossible de creer le fichier $opt_o\n";
print SORTIE time, " ";
} else {
open(SORTIE,">-");
}
# Si pas de message defini
if (! defined($opt_m) ) {
$opt_m = $0 . ' ' . join(' ', @ARGV);
}
printf SORTIE "%s %s\n", $opt_m, "$output";
close(SORTIE);
--
Gildas PERROT, perrot@francenet.fr __o
FranceNet, 28 rue Desaix, 75015 Paris ---_ \<,_
---- (_)/ (_)