From fe13de2096c5a93096cff2cf671ce58620fbfd3c Mon Sep 17 00:00:00 2001 From: akr Date: Mon, 5 Sep 2005 15:02:10 +0000 Subject: [PATCH] document a blocking behavior of IO#eof?. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9084 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- io.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/io.c b/io.c index c1081a7464..474e20b9fa 100644 --- a/io.c +++ b/io.c @@ -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