diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/unicorn/chunked_reader.rb | 17 | ||||
-rw-r--r-- | lib/unicorn/tee_input.rb | 31 |
2 files changed, 17 insertions, 31 deletions
diff --git a/lib/unicorn/chunked_reader.rb b/lib/unicorn/chunked_reader.rb index 539b350..b813da6 100644 --- a/lib/unicorn/chunked_reader.rb +++ b/lib/unicorn/chunked_reader.rb @@ -32,23 +32,6 @@ module Unicorn buf end - def gets - line = nil - begin - line = readpartial(Const::CHUNK_SIZE) - begin - if line.sub!(%r{\A(.*?#{$/})}, Z) - @chunk_left += line.size - @buf = @buf ? (line << @buf) : line - return $1.dup - end - line << readpartial(Const::CHUNK_SIZE) - end while true - rescue EOFError - return line - end - end - private def last_block(max = nil) 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 |