Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Re: $Socket->connected Not Returning False?

by ant9000 (Monk)
on Oct 21, 2003 at 12:58 UTC ( #300893=note: print w/replies, xml ) Need Help??

in reply to $Socket->connected Not Returning False?

You could use sysread like this:
use IO::Socket::INET; my $Socket = IO::Socket::INET->new( PeerAddr=>"" ) or die; $Socket->send("GET /404 HTTP/1.0$/$/") or die; my $still_connected=1; while($still_connected){ my $Byte; my $read=sysread($Socket,$Byte,1); if(defined($read)){ if($read==0){ $still_connected=0; }else{ print "Byte: '$Byte'$/"; } }else{ if($!==EAGAIN()){ print "No byte.$/"; }else{ print "Error $!.$/"; $still_connected=0; } } }


Replies are listed 'Best First'.
Re: Re: $Socket->connected Not Returning False?
by BronzeWing (Monk) on Oct 21, 2003 at 17:55 UTC

    Thank you! I've added a case to my original code that watches for !defined($read) and $! != EAGAIN(), and closes the socket locally, allowing $Socket->connected to return false. It works perfectly now.


    You are in a maze of twisty little knowledge base documents, all alike.
    It is dark. You are likely to be eaten by a lawyer.

Re^2: $Socket->connected Not Returning False?
by ivanatora (Sexton) on Jan 15, 2006 at 09:10 UTC
    What exactly is EAGAIN() ?

      man 2 read. You tried a non-blocking I/O operation which failed because no data was there to be read, and you should try again.

      There are ten types of people: those that understand binary and those that don't.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://300893]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (5)
As of 2023-03-27 19:54 GMT
Find Nodes?
    Voting Booth?
    Which type of climate do you prefer to live in?

    Results (65 votes). Check out past polls.