From: John Holdsworth Date: Sun, 4 Feb 2001 12:48:18 +0000 (+0100) Subject: Allow a zero timeout on IO::Socket accept and connect-- X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=7e92b0959fb4c0f54fe954a74d712d3cd54b1d9b;p=p5sagit%2Fp5-mst-13.2.git 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 --- diff --git a/ext/IO/lib/IO/Socket.pm b/ext/IO/lib/IO/Socket.pm index 8d53136..afe8b27 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 on the socket and return a new object. The -new object will be created in the same class as the listen socket, unless -C 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 on the socket and return a new +object. The new object will be created in the same class as the listen +socket, unless C 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)