From dcd4fce91aa44c5026e9ca3afd8350f53fe1cb0f Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Mon, 2 Nov 2009 01:09:37 -0800 Subject: ev_core: use Tempfile instead of Unicorn::Util::tmpio Since we're geared towards slower clients, we may be able to make gains from using userspace IO buffering. This allows us to avoid metadef-ing a #size method for every File we allocate and save memory. --- lib/rainbows/ev_core.rb | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/lib/rainbows/ev_core.rb b/lib/rainbows/ev_core.rb index 9716d6b..a19648e 100644 --- a/lib/rainbows/ev_core.rb +++ b/lib/rainbows/ev_core.rb @@ -1,5 +1,7 @@ # -*- encoding: binary -*- +require 'tempfile' + module Rainbows # base module for evented models like Rev and EventMachine @@ -36,15 +38,6 @@ module Rainbows quit end - def tmpio - io = Util.tmpio - def io.size - # already sync=true at creation, so no need to flush before stat - stat.size - end - io - end - # TeeInput doesn't map too well to this right now... def on_read(data) case @state @@ -62,7 +55,8 @@ module Rainbows write(EXPECT_100_RESPONSE) @env.delete(HTTP_EXPECT) end - @input = len && len <= MAX_BODY ? StringIO.new("") : tmpio + @input = len && len <= MAX_BODY ? + StringIO.new("") : Tempfile.new(nil).binmode @hp.filter_body(@buf2 = @buf.dup, @buf) @input << @buf2 on_read("") @@ -77,7 +71,10 @@ module Rainbows on_read("") end when :trailers - @hp.trailers(@env, @buf << data) and app_call + if @hp.trailers(@env, @buf << data) + app_call + @input.close! if Tempfile === @input + end end rescue Object => e handle_error(e) -- cgit v1.2.3-24-ge0c7