On Fri, Nov 30, 2001 at 02:21:53PM -0500, Ken Hammer wrote:
> our flag;
> sub alarm_handler
> {
> set flag;
> }
>
> set alarm to expire after 10 secs;
> Loop indefinitely {
> exit if ($flag);
> my $response = $ua->request($req);
> my $content = $response->content();
> }
This is more pseudo-code than actual code, as you've found out. The working
version of the code looks something like:
our $flag;
sub alarm_handler { $flag++ }
alarm(10);
while (1) {
exit if $flag;
my $response = $ua->request($req);
my $content = $response->content();
}
Even turning it into actual code doesn't make it work: the $SIG{ALRM}
assignment is missing, the alarm is never unset, and the loop loops forever
despite the success of the request. I wouldn't suggest this approach
anyway. I would suggest something more along the lines of:
eval {
local $SIG{ALRM}; # just in case someone else set a handler
alarm(10);
my $response = $ua->request($req);
my $content = $response->content();
alarm(0);
};
Actually, given that you're using LWP::UserAgent, I would suggest simply
calling the timeout method.
$ua->timeout(10);
Your connection should then be automatically timed out.
For documentation on the above see perldoc -q 'timeout' (follow the
references), perldoc perlipc (search for alarm), and perldoc LWP::UserAgent.
Michael
--
Administrator www.shoebox.net
Programmer, System Administrator www.gallanttech.com
--
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]