2013-11-23 27 views
1

我使用HTTP::Tiny + IO::Socket::Socks::Wrapper通过SOCKS代理发送HTTP请求。除了超时选项外,一切正常。 当仅使用IO :: Socket :: Socks而不使用HTTP :: Tiny时,超时正在工作。Perl HTTP Tiny +套接字袜子包装超时不起作用

实施例而不HTTP ::微小和不存在的代理触发超时:

my $t = time; 
my $sock = IO::Socket::Socks->new(
    ProxyAddr => '4.5.6.7', 
    ProxyPort => 1080, 
    ConnectAddr => 'www.google.com', 
    ConnectPort => 80, 
    Timeout => 3 
) or print "connection failed or timed out\n"; 

print "time: " . (time - $t) . "\n"; 

输出:

connection failed or timed out 
time: 3.00517201423645 

实施例与HTTP ::微小:

my $t = time; 
my $http = wrap_connection(
    HTTP::Tiny->new(timeout => 3), { 
     ProxyAddr => '4.5.6.7', 
     ProxyPort => 1080, 
     Timeout => 3 
    } 
); 
my $r = $http->get("http://www.google.com"); 
print "connection failed or timed out\n" unless $r->{success}; 
print "time: " . (time - $t) . "\n"; 

输出:

connection failed or timed out 
time: 21.0282030105591 

为什么第二个示例在3秒后不超时?

回答

1

这是一个bug,现在看来已经修复了。新版本将很快上传到CPAN。 而现在你可以从github回购获得固定版本。