On Sun, 23 Oct 2005 noreply / rubyforge.org wrote:

> Bugs item #2702, was opened at 2005-10-23 14:48
> You can respond by visiting:
> http://rubyforge.org/tracker/?func=detail&atid=1698&aid=2702&group_id=426
>
> Category: Core
> Group: None
> Status: Open
> Resolution: None
> Priority: 3
> Submitted By: Tom Payne (twp)
> Assigned to: Nobody (None)
> Summary: IO#sysread incorrectly raises EOFError if underlying call to read(2) returns 0
>
> Initial Comment:
> The system call read(2) returns 0 if there are currently no data to read.
> This does not necessarily mean that there is an error or and end-of-file,
> simply that there are no data available now. This can happen if, for
> example, the IO object has been opened in non-blocking mode.
>
> IO#sysread (rb_io_sysread in io.c) interprets a return value of 0 as being an EOF error in these lines, approx lines 2414-2417 of io.c:
>
>    ...
>    rb_str_resize(str, n);
>    if (n == 0 && ilen > 0) {
> 	rb_eof_error();
>    }
>    ...
>
> This behaviour is incorrect, instead the IO#sysread should simply return an
> empty string if the underlying call to read(2) returned zero.

are you sure?  man 2 read (linux) says:

...
ERRORS
...
        EAGAIN Non-blocking  I/O has been selected using O_NONBLOCK and no data
               was immediately available for reading.
...

and this certainly works:

   harp:~ > mkfifo fifo

   harp:~ > ruby -e' f = open("fifo", File::RDWR | File::NONBLOCK) and f.sysread(42) '
   -e:1:in `sysread': Resource temporarily unavailable - fifo (Errno::EAGAIN)
           from -e:1

the read call is definitely returning -1 in this case:

   harp:~ > strace ruby -e' f = open("fifo", File::RDWR | File::NONBLOCK) and f.sysread(42) ' 2>&1 |egrep ^read|tail -1
   read(3, 0x8f37b60, 42)                  = -1 EAGAIN (Resource temporarily unavailable)

are there platforms that return a zero instead of -1 and errno == EAGAIN in
this case?

cheers.

-a
-- 
===============================================================================
| email :: ara [dot] t [dot] howard [at] noaa [dot] gov
| phone :: 303.497.6469
| anything that contradicts experience and logic should be abandoned.
| -- h.h. the 14th dalai lama
===============================================================================