--Boundary_(ID_7jYW9YVuvyxVA4b4l+OBuQ)
Content-type: TEXT/PLAIN; format=flowed; charset=X-UNKNOWN
Content-transfer-encoding: QUOTED-PRINTABLE

On Thu, 27 Mar 2008, IƱaki Baz Castillo wrote:

> ...
> sigprocmask(SIG_BLOCK, NULL, [])        = 0
> sigprocmask(SIG_BLOCK, NULL, [])        = 0
> sigprocmask(SIG_BLOCK, NULL, [])        = 0
> sigprocmask(SIG_BLOCK, NULL, [])        = 0
> sigprocmask(SIG_BLOCK, NULL, [])        = 0
> select(4, [3], [], [], {0, 0})          = 0 (Timeout)  <---
> sigprocmask(SIG_BLOCK, NULL, [])        = 0
> sigprocmask(SIG_BLOCK, NULL, [])        = 0
> sigprocmask(SIG_BLOCK, NULL, [])        = 0
> sigprocmask(SIG_BLOCK, NULL, [])        = 0
> sigprocmask(SIG_BLOCK, NULL, [])        = 0

My guess is if you include the read statements you get something likehis...
   read(3, "", 1000)                       = 0
Which means (according to "man 2 read")
   On success, the number of bytes read is returned (zero indicates end of file)

If you read "man select_tut"
        9.     If the functions read(2), recv(2), write(2), and send(2) fail  with  errors  other  than  those
               listed  in 7., or one of the input functions returns 0, indicating end of file, then you should
               not pass that descriptor to select() again.  In the above example, I close the descriptor imme               diately, and then set it to -1 to prevent it being included in a set.

Thus...

mkfifo foofi
ruby -w test.rb&
echo bah > foofi

==test.rb=============================================================
loop do
    begin
       open( "foofi") do |f|
          loop do
             p select([f],nil,nil,500000)
             p f.sysread(1000)
          end
       end
    rescue EOFError => details
       p details
    end
end
======================================================================
Works as expected...

But...

======================================================================
open( "foofi") do |f|
    loop do
      p select([f],nil,nil,500000)
      p f.sysread(1000)
    end
end
======================================================================

Bombs out with EOFError

but curiously
======================================================================
open( "foofi") do |f|
    loop do
       p select([f],nil,nil,500000)
       p f.read(1000)
    end
end
======================================================================
Exhibits exactly the behaviour you describe.

Looking at the strace....
open("foofi", O_RDONLY|O_LARGEFILE)     = 9
select(10, [9], NULL, NULL, {500000, 0}) = 1 (in [9], left {500000,})
fstat64(1, {st_dev=makedev(0, 11), st_ino=37, st_mode=S_IFCHR|0620, st_nlink=1, st_uid=1001, st_gid=5, st_blksize=1024, st_blocks=0, st_rdev=makedev(136, 35), st_atime=2008/03/27-14:45:52, st_mtime=2008/03/27-14:45:52, st_ctime=2008/03/27-14:45:52}) = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb7db2000
write(1, "[[#<File:foofi>], [], []]\n", 26) = 26
fstat64(9, {st_dev=makedev(8, 3), st_ino=2375703, st_mode=S_IFIFO|0644, st_nlink=1, st_uid=1001, st_gid=65534, st_blksize=4096, st_blocks=0, st_size=0, st_atime=2008/03/27-14:43:56, st_mtime=2008/03/27-14:45:54, st_ctime=2008/03/27-14:45:54}) = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb7db1000
read(9, "bah\n", 4096)                  = 4
read(9, "", 4096)                       = 0
write(1, "\"bah\\n\"\n", 8)             = 8
select(10, [9], NULL, NULL, {500000, 0}) = 1 (in [9], left {500000,})
write(1, "[[#<File:foofi>], [], []]\n", 26) = 26
write(1, "nil\n", 4)                    = 4
select(10, [9], NULL, NULL, {500000, 0}) = 1 (in [9], left {500000,})
write(1, "[[#<File:foofi>], [], []]\n", 26) = 26
write(1, "nil\n", 4)                    = 4

The curiosity is why doesn't the f.read throw an EOFError

According to ri IO#read...

      At end of file, it returns nil or "" depend on length.
      ios.read() and ios.read(nil) returns "".
      ios.read(positive-integer) returns nil.

So it all behaves according to plan... just not your plan... :-))

John Carter                             Phone : (64)(3) 358 6639
Tait Electronics                        Fax   : (64)(3) 359 4632
PO Box 1645 Christchurch                Email : john.carter / tait.co.nz
New Zealand

--Boundary_(ID_7jYW9YVuvyxVA4b4l+OBuQ)--