【问题标题】:Perl HTTP Tiny + Socket Socks Wrapper Timeout not workingPerl HTTP Tiny + Socket Socks Wrapper Timeout 不起作用
【发布时间】:2013-12-08 18:05:10
【问题描述】:

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

没有 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 秒后没有超时?

【问题讨论】:

    标签: perl sockets http timeout socks


    【解决方案1】:

    这是一个错误,现在似乎已修复。新版本将很快上传到 CPAN。 现在你可以从 github repo 获得固定版本。

    【讨论】:

      猜你喜欢
      • 2018-07-14
      • 2018-12-24
      • 1970-01-01
      • 2012-03-08
      • 2011-12-27
      • 2018-12-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多