develooper Front page | perl.perl5.porters | Postings from April 2004

Re: [perl #29019] nonblocking read returns EAGAIN at eof

Thread Previous | Thread Next
From:
Nicholas Clark
Date:
April 29, 2004 09:20
Subject:
Re: [perl #29019] nonblocking read returns EAGAIN at eof
Message ID:
20040429162034.GT701@plum.flirble.org
On Wed, Apr 21, 2004 at 03:46:43AM -0000, David Muir Sharnoff wrote:

> On a non-blocking socket when there is nothing more
> to read and the other side has closed the connection,
> read() returns undef and sets $! to EAGAIN.
> 
> Unix behavior in this situation is to return zero byte
> and no error.

perl's read() is doing buffered IO, equivalent to C's fread()
Hence you're mixing buffered IO and non blocking file descriptors, which is
bad

> I believe perl should follow the Unix behavior.  It's already
> hard enough to detect EOF on non-blocking sockets.

If you use sysread instead of read you shouldn't have a problem.

Nicholas Clark

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About