From d3c20360f9607a9e04f7d28ce0a796437f733e5f Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Thu, 5 Nov 2009 00:49:06 -0800 Subject: Util::tmpio returns a TmpIO that responds to #size Subclass off the core File class so we don't have to worry about #size being defined. This will mainly be useful to Rainbows! but allows us to simplify our TeeInput implementation a little, too. --- lib/unicorn/tee_input.rb | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'lib/unicorn/tee_input.rb') diff --git a/lib/unicorn/tee_input.rb b/lib/unicorn/tee_input.rb index b66dce0..474f10f 100644 --- a/lib/unicorn/tee_input.rb +++ b/lib/unicorn/tee_input.rb @@ -38,7 +38,7 @@ module Unicorn @tmp.seek(pos) end - @size = tmp_size + @size = @tmp.size end # call-seq: @@ -73,7 +73,7 @@ module Unicorn rv else rv = args.shift || @buf2.dup - diff = tmp_size - @tmp.pos + diff = @tmp.size - @tmp.pos if 0 == diff ensure_length(tee(length, rv), length) else @@ -87,7 +87,7 @@ module Unicorn socket or return @tmp.gets nil == $/ and return read - orig_size = tmp_size + orig_size = @tmp.size if @tmp.pos == orig_size tee(Const::CHUNK_SIZE, @buf2) or return nil @tmp.seek(orig_size) @@ -147,10 +147,6 @@ module Unicorn self.socket = nil end - def tmp_size - StringIO === @tmp ? @tmp.size : @tmp.stat.size - end - # tee()s into +buf+ until it is of +length+ bytes (or until # we've reached the Content-Length of the request body). # Returns +buf+ (the exact object, not a duplicate) -- cgit v1.2.3-24-ge0c7