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 30, 2004 02:53
Subject:
Re: [perl #29019] nonblocking read returns EAGAIN at eof
Message ID:
20040430095335.GX701@plum.flirble.org
On Thu, Apr 29, 2004 at 02:22:04PM -0700, David Muir Sharnoff wrote:
> * 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.
> 
> If I use sysread() intead of read() then I can't use eof() at all
> because eof does getc()/ungetc() internally.  I don't see any reason
> for perl's read() to return EAGAIN at eof().

True, but you can detect EOF by a sysread of 0.

> The man page for fread() says that it should return 0 at EOF.

Non-blocking IO and buffered IO don't mix.
At least for C's stdio, and perl's IO.

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