Foo Ji-Haw wrote:

> Hello guys,
> 
> I seem to be stuck with this one. Need your expert input on this.
> 
> I used a IO::Socket::INET object to connect to a whois server (port 43, 
> and no I'm not trying to parse emails to spam!). I send the domain name 
> and read back the whois information. Information is returned as a series 
> of strings. Half the time everything is ok. Sometimes the reading is 
> 'stuck'; the object cannot return the next string, causing the whole 
> program to hang. Below is the code snippet:
> 
>         my $socket = IO::Socket::INET->new(
>                             PeerAddr=>$WHOISServer,
>                             PeerPort=>'43',
>                             Proto=>'tcp',
>                             Timeout=>5,
>                             Type=>SOCK_STREAM,
>                             );
>         return undef if (!$socket);
>         while (my $line = <$socket>)
>         {
>             print "=>$line";
>         }
> 
> I did a Telnet, and I get the same experience. Sometimes the first few 
> lines will come out, then the screen freezes. The only difference is 
> that if I press the Enter key a few times Telnet will move on and 
> disconnect. I interprete this as perhaps the buffer needs to be flushed. 
> Unfortunately, according to the documentation autoflush is on by 
> default. So I am at my wit's end.
> 
> I need a way to make sure my program does not hang here. Is there any 
> way I can timeout the reading (notice my Timeout setting in the code. 
> Did not work when reading)?

You could use IO::Select and poll the FH before reading or you could try
Blocking => 0 for an arg for non-blocking and add a sleep in there to
release control/CPU.  The Timeout => 5 will probably not help on Windoze.

-- 
  ,-/-  __      _  _         $Bill Luebkert    Mailto:[EMAIL PROTECTED]
 (_/   /  )    // //       DBE Collectibles    Mailto:[EMAIL PROTECTED]
  / ) /--<  o // //      Castle of Medieval Myth & Magic http://www.todbe.com/
-/-' /___/_<_</_</_    http://dbecoll.tripod.com/ (My Perl/Lakers stuff)
_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to