Re: [Fwd: IO::Socket::connect and blocking]
Benjamin Low [Fri, 8 Jan 1999 14:36:53 +0000 (01:36 +1100)]
Message-ID: <36957D55.1D65A0B2@unsw.edu.au>

p4raw-id: //depot/perl@2868

ext/IO/lib/IO/Socket.pm

index 894190f..0bdf2ff 100644 (file)
@@ -22,7 +22,7 @@ require IO::Socket::UNIX;
 
 @ISA = qw(IO::Handle);
 
-$VERSION = "1.25";
+$VERSION = "1.251";
 
 sub import {
     my $pkg = shift;
@@ -101,39 +101,34 @@ sub connect {
     my $addr = shift;
     my $timeout = ${*$sock}{'io_socket_timeout'};
 
-    eval {
-       my $blocking = 0;
+    my $blocking;
+    $blocking = $sock->blocking(0) if $timeout;
 
+    eval {
        croak 'connect: Bad address'
            if(@_ == 2 && !defined $_[1]);
 
-       $blocking = $sock->blocking(0)
-           if($timeout);
-
        unless(connect($sock, $addr)) {
            if($timeout && ($! == &IO::EINPROGRESS)) {
                require IO::Select;
 
                my $sel = new IO::Select $sock;
 
-               $sock->blocking(1)
-                   if($blocking);
-
                unless($sel->can_write($timeout) && defined($sock->peername)) {
-                   undef $sock;
                    croak "connect: timeout";
                }
            }
            else {
-               undef $sock;
                croak "connect: $!";
            }
        }
-       $sock->blocking(1)
-           if($sock && $blocking);
     };
 
-    $sock;
+    my $ret = $@ ? undef : $sock;
+
+    $sock->blocking($blocking) if $timeout;
+
+    $ret;
 }
 
 sub bind {