Hi,
in order to handle requests that take some time to complete (~90sec) it would be nice to be able to specify different timouts for connect (which should be quite fast) and read. This is nice if the host you try to access is hidden behind a firewall so that you can't connect, but you do not get a "connection closed" or "connection refused".
The following packages implement this (2 sec) connect timeout. I suggest, that this type of code is added to the LWP code, where the connect_timeout is set to the global timeout unless otherwise specified. Any comments welcome.
Regards
Martin
PS: An analogue example works for LWP::Parallel and is very useful for parallel requests where some of the hosts can't be accessed
package HGF::Protocol::http;
use base qw(LWP::Protocol::http);
# Implements a connect timeout of 2 sec
sub _new_socket {
my $self=shift;
my $timeout = pop(@_);
push(@_,2);
my $ret =$self->SUPER::_new_socket(@_);
$ret->timeout($timeout);
return $ret;
};
package HGF::Protocol::http::Socket;
use vars qw(@ISA);
@ISA = qw(LWP::Protocol::http::Socket);
1;
use LWP::UserAgent;
use LWP::Protocol;
use HGF::Protocol::http;
LWP::Protocol::implementor('http','HGF::Protocol::http');