From: Tanaka Akira Date: 2005-09-06T20:29:36+09:00 Subject: Re: Nonblocking and/or win32 (was: Re: [ANN] EventLoop 0.0.20050825.1600) In article <0ca201c5b19d$6368edd0$6442a8c0@musicbox>, "Bill Kelly" writes: > Is it not possible to check for EOF without blocking? I documented the blocking behavior of IO#eof?. I hope it reduces confusion about IO#eof?. Index: io.c =================================================================== RCS file: /src/ruby/io.c,v retrieving revision 1.376 diff -u -p -r1.376 io.c --- io.c 30 Aug 2005 14:49:51 -0000 1.376 +++ io.c 5 Sep 2005 14:52:58 -0000 @@ -908,12 +908,31 @@ io_getc(OpenFile *fptr) * ios.eof => true or false * ios.eof? => true or false * - * Returns true if ios is at end of file. The stream must be - * opened for reading or an IOError will be raised. + * Returns true if ios is at end of file that means + * there are no more data to read. + * The stream must be opened for reading or an IOError will be + * raised. * * f = File.new("testfile") * dummy = f.readlines * f.eof #=> true + * + * If ios is a stream such as pipe or socket, IO#eof? + * blocks until the other end sends some data or closes it. + * + * r, w = IO.pipe + * Thread.new { sleep 1; w.close } + * r.eof? #=> true after 1 second blocking + * + * r, w = IO.pipe + * Thread.new { sleep 1; w.puts "a" } + * r.eof? #=> false after 1 second blocking + * + * r, w = IO.pipe + * r.eof? # blocks forever + * + * Note that IO#eof? reads data to a input buffer. + * So IO#sysread doesn't work with IO#eof?. */ VALUE -- Tanaka Akira