about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2009-11-02 01:09:37 -0800
committerEric Wong <normalperson@yhbt.net>2009-11-02 10:02:29 -0800
commitdcd4fce91aa44c5026e9ca3afd8350f53fe1cb0f (patch)
tree06694d8c85de4b2a0555f0c55bfa7e4da32a3447
parent5c16fb386508de6eccda9d0b1cf3995e98717543 (diff)
downloadrainbows-dcd4fce91aa44c5026e9ca3afd8350f53fe1cb0f.tar.gz
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.
-rw-r--r--lib/rainbows/ev_core.rb19
1 files 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)