diff options
author | Eric Wong <normalperson@yhbt.net> | 2009-07-16 01:13:33 -0700 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2009-07-16 01:13:33 -0700 |
commit | 2e913054b36848a05f7ba06c3accbe164c666708 (patch) | |
tree | 3dbac8d2be3f7ba7a00cd23fff146c40e0a3d747 /lib/unicorn | |
parent | a0f2c4514e969d0a127227201cbdb8e57f71df63 (diff) | |
download | unicorn-2e913054b36848a05f7ba06c3accbe164c666708.tar.gz |
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.
Diffstat (limited to 'lib/unicorn')
-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 |