From 2bb3f8fd600bd0aabe5e4d7c3d1f99d745fc8f49 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Thu, 9 Dec 2010 17:14:04 -0800 Subject: respect client_body_buffer_size in Unicorn 3.1.0 This is only needed for concurrency options that do not use TeeInput, since TeeInput automatically handles this for us. --- lib/rainbows/ev_core.rb | 14 +++++++++++--- lib/rainbows/ev_core/cap_input.rb | 5 +++-- lib/rainbows/event_machine.rb | 1 + lib/rainbows/rev/core.rb | 1 + 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/lib/rainbows/ev_core.rb b/lib/rainbows/ev_core.rb index 46fdedf..6f1b5e5 100644 --- a/lib/rainbows/ev_core.rb +++ b/lib/rainbows/ev_core.rb @@ -108,8 +108,12 @@ module Rainbows::EvCore raise IOError, msg, [] end - MAX_BODY = Unicorn::Const::MAX_BODY TmpIO = Unicorn::TmpIO + + def io_for(bytes) + bytes <= CBB ? StringIO.new("") : TmpIO.new + end + def mkinput max = Rainbows.max_bytes len = @hp.content_length @@ -117,9 +121,13 @@ module Rainbows::EvCore if max && (len > max) err_413("Content-Length too big: #{len} > #{max}") end - len <= MAX_BODY ? StringIO.new("") : TmpIO.new + io_for(len) else - max ? CapInput.new(TmpIO.new, self) : TmpIO.new + max ? CapInput.new(io_for(max), self, max) : TmpIO.new end end + + def self.setup + const_set :CBB, Unicorn::TeeInput.client_body_buffer_size + end end diff --git a/lib/rainbows/ev_core/cap_input.rb b/lib/rainbows/ev_core/cap_input.rb index a2eecab..4865da4 100644 --- a/lib/rainbows/ev_core/cap_input.rb +++ b/lib/rainbows/ev_core/cap_input.rb @@ -1,8 +1,9 @@ # -*- encoding: binary -*- # :enddoc: class Rainbows::EvCore::CapInput - def initialize(io, client) - @io, @client, @bytes_left = io, client, Rainbows.max_bytes + + def initialize(io, client, max) + @io, @client, @bytes_left = io, client, max end def <<(buf) diff --git a/lib/rainbows/event_machine.rb b/lib/rainbows/event_machine.rb index a33fcf7..99fa32e 100644 --- a/lib/rainbows/event_machine.rb +++ b/lib/rainbows/event_machine.rb @@ -199,6 +199,7 @@ module Rainbows::EventMachine Server.const_set(:MAX, worker_connections + LISTENERS.size) Server.const_set(:CL, client_class) client_class.const_set(:APP, G.server.app) + Rainbows::EvCore.setup EM.run { conns = EM.instance_variable_get(:@conns) or raise RuntimeError, "EM @conns instance variable not accessible!" diff --git a/lib/rainbows/rev/core.rb b/lib/rainbows/rev/core.rb index abd7ca7..5c5b799 100644 --- a/lib/rainbows/rev/core.rb +++ b/lib/rainbows/rev/core.rb @@ -31,6 +31,7 @@ module Rainbows Server.const_set(:MAX, @worker_connections) Server.const_set(:CL, mod.const_get(:Client)) EvCore.const_set(:APP, G.server.app) + Rainbows::EvCore.setup Heartbeat.new(1, true).attach(rloop) LISTENERS.map! { |s| Server.new(s).attach(rloop) } rloop.run -- cgit v1.2.3-24-ge0c7