diff options
-rw-r--r-- | lib/unicorn/tee_input.rb | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/lib/unicorn/tee_input.rb b/lib/unicorn/tee_input.rb index ac9638d..7bc4e10 100644 --- a/lib/unicorn/tee_input.rb +++ b/lib/unicorn/tee_input.rb @@ -32,6 +32,7 @@ module Unicorn buf = Z.dup while tee(Const::CHUNK_SIZE, buf) end + @rd.rewind self end @@ -58,7 +59,12 @@ module Unicorn rv else buf = args.shift || Z.dup - @rd.read(length, buf) || tee(length, buf) + diff = @wr.stat.size - @rd.pos + if 0 == diff + tee(length, buf) + else + @rd.read(diff > length ? length : diff, buf) + end end end @@ -75,12 +81,14 @@ module Unicorn # half the line was already read, and the rest of has not been read if buf = @input.gets @wr.write(buf) + @rd.seek(@wr.stat.size) line << buf else @input = nil end elsif line = @input.gets @wr.write(line) + @rd.seek(@wr.stat.size) end line @@ -122,6 +130,7 @@ module Unicorn return @input = nil end @wr.write(buf) + @rd.seek(@wr.stat.size) buf end |