Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

IO::Socket::INET Timeout Issue

by Hrunting (Pilgrim)
on Feb 07, 2001 at 00:26 UTC ( [id://56769]=perlquestion: print w/replies, xml ) Need Help??

Hrunting has asked for the wisdom of the Perl Monks concerning the following question:

I was using Net::FTP and ran into a problem. None of the FTP sites I was trying to connect to would return a connection. Net::FTP (which subclasses IO::Socket) was returning a timeout (despite the fact that I could get to any and all FTP sites very quickly). Net::FTP defaults to a Timeout of 120 on those connections, and it was returning almost immediately, it seemed.

I tried passing in an explicity Timeout of 0 and sure enough, things connected as expected. Apparently, this is related to IO::Socket::INET as I could reproduce the behavior there.

Did something change in this module. Apparently, if I have any Timeout value specified, the socket times out, but if I explicitly pass in a 0 value or don't pass in a Timeout value at all, things work as they should. Is Timeout a boolean (the IO::Socket::INET manpage just says 'Timeout value for various operations', which I assume would be seconds (as do almost every other module that I use).

For some more information, this a fresh build of perl 5.6.0 on a RedHat 7.0-based i586 Linux install (kernel 2.2.18). Compilation is done using gcc 2.96 20000731.

Replies are listed 'Best First'.
Re: IO::Socket::INET Timeout Issue
by Fastolfe (Vicar) on Feb 07, 2001 at 00:28 UTC
    Can you reduce this to a test case using IO::Socket::INET itself and not relying on Net::FTP? The Timeout field here is (as I understand) exactly as you expect: It's the number of seconds it should wait before giving up.
      Yeah, I did that. That's how I determined that the problem was with IO::Select::INET and not with anything else. My test code was:
      #!/usr/bin/perl use strict; use IO::Select::INET; my $sock = IO::Select::INET->new( PeerAddr => '(host)', # where host is some host I knew PeerPort => 'ftp(21)', # or http(80) or whatever Proto => 'tcp' ); print defined $sock ? 'Connected!' : $@, "\n"; exit 0;
      And then again with Timeout => 0 and Timeout => 120. It was successful on all of them except for Timeout => 120, which it failed to connect (and not after 120 seconds).

      Might I add to this that the reason IO::Socket::INET is giving for not creating the socket (as returned by $@) is 'IO::Socket::INET: Timeout'. Since I can connect when no Timeout is specified, I think I've at least narrowed it down to a problem within the module and not something en route causing a connection failure.

        5.6 on Solaris runs your test code fine (except I changed 'use IO::Select::INET' to 'use IO::Socket' and 'IO::Select::INET->new' to 'IO::Socket::INET->new'), with no timeout specified, 0, 120, 500, whatever.

        I'm curious what version of IO::Socket you have on your system? I'm using 1.1602 here.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://56769]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (5)
As of 2024-04-20 01:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found