diff options
author | John Holdsworth <coldwave@bigfoot.com> | 2001-02-04 13:48:18 +0100 |
---|---|---|
committer | Jarkko Hietaniemi <jhi@iki.fi> | 2001-04-30 12:22:15 +0000 |
commit | 7e92b0959fb4c0f54fe954a74d712d3cd54b1d9b (patch) | |
tree | 113f2676ab92302e34ae02e443ab12faa6a8e568 /ext/IO/lib | |
parent | 31376155686abbaa42a7be07601c13aa942b9461 (diff) | |
download | perl-7e92b0959fb4c0f54fe954a74d712d3cd54b1d9b.tar.gz |
Allow a zero timeout on IO::Socket accept and connect--
though one really shouldn't do that. Based on
Subject: Not possible to set zero second timeout on accept() in IO::Socket and company..
Message-ID: <005a01c08ea0$5e6039d0$03ac2ac0@planc>
p4raw-id: //depot/perl@9913
Diffstat (limited to 'ext/IO/lib')
-rw-r--r-- | ext/IO/lib/IO/Socket.pm | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/ext/IO/lib/IO/Socket.pm b/ext/IO/lib/IO/Socket.pm index 8d53136ea7..afe8b27596 100644 --- a/ext/IO/lib/IO/Socket.pm +++ b/ext/IO/lib/IO/Socket.pm @@ -112,7 +112,7 @@ sub connect { $blocking = $sock->blocking(0) if $timeout; if (!connect($sock, $addr)) { - if ($timeout && $!{EINPROGRESS}) { + if (defined $timeout && $!{EINPROGRESS}) { require IO::Select; my $sel = new IO::Select $sock; @@ -168,7 +168,7 @@ sub accept { my $new = $pkg->new(Timeout => $timeout); my $peer = undef; - if($timeout) { + if(defined $timeout) { require IO::Select; my $sel = new IO::Select $sock; @@ -369,13 +369,21 @@ in attempt to make the interface more flexible. These are =item accept([PKG]) -perform the system call C<accept> on the socket and return a new object. The -new object will be created in the same class as the listen socket, unless -C<PKG> is specified. This object can be used to communicate with the client -that was trying to connect. In a scalar context the new socket is returned, -or undef upon failure. In a list context a two-element array is returned -containing the new socket and the peer address; the list will -be empty upon failure. +perform the system call C<accept> on the socket and return a new +object. The new object will be created in the same class as the listen +socket, unless C<PKG> is specified. This object can be used to +communicate with the client that was trying to connect. + +In a scalar context the new socket is returned, or undef upon +failure. In a list context a two-element array is returned containing +the new socket and the peer address; the list will be empty upon +failure. + +The timeout in the [PKG] can be specified as zero to effect a "poll", +but you shouldn't do that because a new IO::Select object will be +created behind the scenes just do to the single poll. This is +horrendously inefficient. Use rather true select() with a zero +timeout on the handle, or non-blocking IO. =item socketpair(DOMAIN, TYPE, PROTOCOL) |