From 2e913054b36848a05f7ba06c3accbe164c666708 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Thu, 16 Jul 2009 01:13:33 -0700 Subject: move all #gets logic to tee_input out of chunked_reader This simplifies chunked_reader substantially with a slight increase in tee_input complexity. This is beneficial because chunked_reader is more complex to begin with and more likely to experience correctness issues. --- lib/unicorn/tee_input.rb | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) (limited to 'lib/unicorn/tee_input.rb') diff --git a/lib/unicorn/tee_input.rb b/lib/unicorn/tee_input.rb index 06028a6..1bcbf1d 100644 --- a/lib/unicorn/tee_input.rb +++ b/lib/unicorn/tee_input.rb @@ -73,22 +73,25 @@ module Unicorn @input or return @tmp.gets nil == $/ and return read - line = nil - if @tmp.pos < @tmp.stat.size - line = @tmp.gets # cannot be nil here - $/ == line[-$/.size, $/.size] and return line - - # half the line was already read, and the rest of has not been read - if buf = @input.gets - @tmp.write(buf) - line << buf - else - @input = nil - end - elsif line = @input.gets - @tmp.write(line) + orig_size = @tmp.stat.size + if @tmp.pos == orig_size + tee(Const::CHUNK_SIZE, Z.dup) or return nil + @tmp.seek(orig_size) end + line = @tmp.gets # cannot be nil here since size > pos + $/ == line[-$/.size, $/.size] and return line + + # unlikely, if we got here, then @tmp is at EOF + begin + orig_size = @tmp.stat.size + tee(Const::CHUNK_SIZE, Z.dup) or break + @tmp.seek(orig_size) + line << @tmp.gets + $/ == line[-$/.size, $/.size] and return line + # @tmp is at EOF again here, retry the loop + end while true + line end -- cgit v1.2.3-24-ge0c7