summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2009-06-29 04:58:21 -0700
committerEric Wong <normalperson@yhbt.net>2009-06-29 04:58:21 -0700
commit0d3aa1eb6bc7646c9bde78b0fae4e34bc5876421 (patch)
tree7b52eb865b9b6b35c9dda004371751fe019a8856
parentcfed47020a39291504877ce2a3463ed268fed9c8 (diff)
Oops!
-rw-r--r--lib/unicorn/tee_input.rb11
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