From 0d3aa1eb6bc7646c9bde78b0fae4e34bc5876421 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Mon, 29 Jun 2009 04:58:21 -0700 Subject: tee_input: avoid rereading fresh data Oops! --- lib/unicorn/tee_input.rb | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) 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 -- cgit v1.2.3-24-ge0c7