From: James Edward Gray II Date: 2007-01-28T15:01:01+09:00 Subject: Re: Net::HTTP Closes STDIN 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? > > $ cat test.rb > puts "closed? %p" % $stdin.closed? > puts "eof? %p" % $stdin.eof? > > require 'net/http' > require 'io/wait' > > Net::HTTP.start('localhost', 80) do |http| > body = http.get('/').body > end > > puts "closed? %p" % $stdin.closed? > puts "eof? %p" % $stdin.eof? > > $ 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? In that case, why does Ruby not need for something to be flushed in that case and why is eof? () then +true+? James Edward Gray II