diff options
author | Raul Dias <raul@dias.com.br> | 2001-10-19 19:45:32 -0300 |
---|---|---|
committer | Jarkko Hietaniemi <jhi@iki.fi> | 2001-10-20 01:02:26 +0000 |
commit | ae1c8c834e40d14abc2481f3159cae29d6d2bc25 (patch) | |
tree | 6e79e20f5f761385c5c9840fcc318645003a15ac | |
parent | b23d7fc6dfda4fd509428852e5292adff219f907 (diff) | |
download | perl-ae1c8c834e40d14abc2481f3159cae29d6d2bc25.tar.gz |
IO module with nonblocking socket connect patch
Message-Id: <200110200145.f9K1jWW08398@stratus.swi.com.br>
p4raw-id: //depot/perl@12520
-rw-r--r-- | ext/IO/lib/IO/Socket.pm | 6 | ||||
-rw-r--r-- | ext/IO/lib/IO/Socket/INET.pm | 7 |
2 files changed, 9 insertions, 4 deletions
diff --git a/ext/IO/lib/IO/Socket.pm b/ext/IO/lib/IO/Socket.pm index b62e7b39dd..d670fe5996 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 051de539cf..62012d7816 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<IO::Socket::INET> 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<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 @@ parameter will be deduced from C<Proto> if not specified. 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', |