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

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

Thread Next
From:
David Muir Sharnoff
Date:
April 30, 2004 02:08
Subject:
Re: [perl #29019] nonblocking read returns EAGAIN at eof
Message ID:
200404292122.i3TLM4nW002259@idiom.com
* 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().

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

-Dave

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