From: Eric Hodel Date: 2007-01-29T18:54:36+09:00 Subject: Re: Net::HTTP Closes STDIN On Jan 27, 2007, at 22:01, James Edward Gray II wrote: > On Jan 27, 2007, at 8:48 PM, Eric Hodel wrote: >> On Jan 27, 2007, at 18:38, James Edward Gray II wrote: >>> On Jan 27, 2007, at 7:39 PM, Eric Hodel wrote: >>> >>>> $stdin isn't closed, its at the end of file. Use #closed? to >>>> test if an IO has been closed or not. >>> >>> Right, good point. >>> >>> However, when I call eof?() before the Net::HTTP call it behaves >>> differently (stalls and prints false). Why does it not behave >>> the same after that page read? >> >> $ ruby test.rb >> closed? false >> type some text here >> eof? false >> closed? false >> eof? false >> $ >> >> For the first #eof? no data written, so Ruby waits until >> something's been flushed. > > OK, that makes sense. However, why does moving that eof?() check > below a Net::HTTP page fetch change this? I don't see this behavior. With your original example I have to hit ^D to get a prompt back. $ ruby -v ruby 1.8.5 (2006-12-04 patchlevel 2) [i686-darwin8.8.2] > In that case, why does Ruby not need for something to be flushed Because #eof? reads a character if feof(3) is not true and there's no data pending: rb_io_eof(io) VALUE io; { OpenFile *fptr; int ch; GetOpenFile(io, fptr); rb_io_check_readable(fptr); if (feof(fptr->f)) return Qtrue; if (READ_DATA_PENDING(fptr->f)) return Qfalse; READ_CHECK(fptr->f); clearerr(fptr->f); TRAP_BEG; ch = getc(fptr->f); ^^^^^^^^^^^^^^^^^^^ Analysis of sampling pid 15640 every 10.000000 milliseconds Call graph: [...] 300 rb_io_eof 300 getc [...] > in that case and why is eof?() then +true+? #eof? will only be true when there's no more data to read. -- Eric Hodel - drbrain@segment7.net - http://blog.segment7.net I LIT YOUR GEM ON FIRE!