Change 12520 by jhi@alpha on 2001/10/20 01:02:26
Subject: IO module with nonblocking socket connect patch
From: Raul Dias <[EMAIL PROTECTED]>
Date: Fri, 19 Oct 2001 22:45:32 -0300
Message-Id: <[EMAIL PROTECTED]>
Affected files ...
... //depot/perl/ext/IO/lib/IO/Socket.pm#26 edit
... //depot/perl/ext/IO/lib/IO/Socket/INET.pm#19 edit
Differences ...
==== //depot/perl/ext/IO/lib/IO/Socket.pm#26 (text) ====
Index: perl/ext/IO/lib/IO/Socket.pm
--- perl/ext/IO/lib/IO/Socket.pm.~1~ Fri Oct 19 19:15:05 2001
+++ perl/ext/IO/lib/IO/Socket.pm Fri Oct 19 19:15:05 2001
@@ -109,8 +109,8 @@
my $timeout = ${*$sock}{'io_socket_timeout'};
my $err;
my $blocking;
+
$blocking = $sock->blocking(0) if $timeout;
-
if (!connect($sock, $addr)) {
if (defined $timeout && $!{EINPROGRESS}) {
require IO::Select;
@@ -121,14 +121,14 @@
$err = $! || (exists &Errno::ETIMEDOUT ? &Errno::ETIMEDOUT : 1);
$@ = "connect: timeout";
}
- elsif(!connect($sock,$addr) && not $!{EISCONN}) {
+ elsif (!connect($sock,$addr) && not $!{EISCONN}) {
# Some systems refuse to re-connect() to
# an already open socket and set errno to EISCONN.
$err = $!;
$@ = "connect: $!";
}
}
- else {
+ elsif ($blocking || !$!{EINPROGRESS}) {
$err = $!;
$@ = "connect: $!";
}
==== //depot/perl/ext/IO/lib/IO/Socket/INET.pm#19 (text) ====
Index: perl/ext/IO/lib/IO/Socket/INET.pm
--- perl/ext/IO/lib/IO/Socket/INET.pm.~1~ Fri Oct 19 19:15:05 2001
+++ perl/ext/IO/lib/IO/Socket/INET.pm Fri Oct 19 19:15:05 2001
@@ -129,6 +129,8 @@
or return _error($sock, $!, $@);
}
+ $sock->blocking($arg->{Blocking}) if defined $arg->{Blocking};
+
$proto ||= (getprotobyname('tcp'))[2];
my $pname = (getprotobynumber($proto))[0];
@@ -309,7 +311,7 @@
ReusePort Set SO_REUSEPORT before binding
Timeout Timeout value for various operations
MultiHomed Try all adresses for multi-homed hosts
-
+ Blocking Determine if connection will be blocking mode
If C<Listen> is defined then a listen socket is created, else if the
socket type, which is derived from the protocol, is SOCK_STREAM then
@@ -335,6 +337,9 @@
If the constructor is only passed a single argument, it is assumed to
be a C<PeerAddr> specification.
+If C<Blocking> is set to 0, the connection will be in nonblocking mode.
+If not specified it defaults to 1 (blocking mode).
+
Examples:
$sock = IO::Socket::INET->new(PeerAddr => 'www.perl.org',
End of Patch.