2013-11-23 56 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回購獲得固定版本。