From: Raul Dias Date: Fri, 19 Oct 2001 22:45:32 +0000 (-0300) Subject: IO module with nonblocking socket connect patch X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=ae1c8c834e40d14abc2481f3159cae29d6d2bc25;p=p5sagit%2Fp5-mst-13.2.git IO module with nonblocking socket connect patch Message-Id: <200110200145.f9K1jWW08398@stratus.swi.com.br> p4raw-id: //depot/perl@12520 --- diff --git a/ext/IO/lib/IO/Socket.pm b/ext/IO/lib/IO/Socket.pm index b62e7b3..d670fe5 100644 --- a/ext/IO/lib/IO/Socket.pm +++ b/ext/IO/lib/IO/Socket.pm @@ -109,8 +109,8 @@ sub connect { my $timeout = ${*$sock}{'io_socket_timeout'}; my $err; my $blocking; - $blocking = $sock->blocking(0) if $timeout; + $blocking = $sock->blocking(0) if $timeout; if (!connect($sock, $addr)) { if (defined $timeout && $!{EINPROGRESS}) { require IO::Select; @@ -121,14 +121,14 @@ sub connect { $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: $!"; } diff --git a/ext/IO/lib/IO/Socket/INET.pm b/ext/IO/lib/IO/Socket/INET.pm index 051de53..62012d7 100644 --- a/ext/IO/lib/IO/Socket/INET.pm +++ b/ext/IO/lib/IO/Socket/INET.pm @@ -129,6 +129,8 @@ sub configure { 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 @@ C provides. 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 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 @@ parameter will be deduced from C if not specified. If the constructor is only passed a single argument, it is assumed to be a C specification. +If C 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',