Perl HTTP Tiny + Socket Socks Wrapper Timeout无效

时间:2013-11-23 22:52:34

标签: perl sockets http timeout socks

我正在使用HTTP::Tiny + IO::Socket::Socks::Wrapper通过SOCKS代理发送HTTP请求。除了超时选项外,一切正常。 当只使用没有HTTP :: Tiny的IO :: Socket :: Socks时,超时工作正常。

没有HTTP :: Tiny的示例和不存在的触发超时的代理:

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 :: Tiny示例:

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 个答案:

答案 0 :(得分:1)

这是bug,现在似乎已经修复了。新版本即将上传至CPAN。 现在你可以从github repo获得固定版本。