From f84f138233be0607b0151a5a28c3f9190ba336a2 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Thu, 28 Oct 2010 08:20:37 +0000 Subject: rev+event_machine: small cleanups with new parser API These allow for small reductions in the amount of variables we have to manage, more changes coming with later Unicorns. --- lib/rainbows/ev_core.rb | 7 ++++--- lib/rainbows/event_machine.rb | 1 - lib/rainbows/rev/client.rb | 3 +-- lib/rainbows/rev/thread.rb | 1 - 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/lib/rainbows/ev_core.rb b/lib/rainbows/ev_core.rb index 200bf79..3865d79 100644 --- a/lib/rainbows/ev_core.rb +++ b/lib/rainbows/ev_core.rb @@ -14,10 +14,10 @@ module Rainbows::EvCore ASYNC_CLOSE = "async.close".freeze def post_init - @env = {} @hp = HttpParser.new + @env = @hp.env + @buf = @hp.buf @state = :headers # [ :body [ :trailers ] ] :app_call :close - @buf = "" end # graceful exit, like SIGQUIT @@ -47,7 +47,8 @@ module Rainbows::EvCore def on_read(data) case @state when :headers - @hp.headers(@env, @buf << data) or return + @buf << data + @hp.parse or return @state = :body len = @hp.content_length if len == 0 diff --git a/lib/rainbows/event_machine.rb b/lib/rainbows/event_machine.rb index 2f363a1..a33fcf7 100644 --- a/lib/rainbows/event_machine.rb +++ b/lib/rainbows/event_machine.rb @@ -94,7 +94,6 @@ module Rainbows::EventMachine alive = @hp.keepalive? && G.alive && G.kato > 0 em_write_response(response, alive) if alive - @env.clear @hp.reset @state = :headers if @buf.empty? diff --git a/lib/rainbows/rev/client.rb b/lib/rainbows/rev/client.rb index 20adbc1..e450d09 100644 --- a/lib/rainbows/rev/client.rb +++ b/lib/rainbows/rev/client.rb @@ -109,7 +109,6 @@ module Rainbows rev_write_response(response, alive = @hp.keepalive? && G.alive) return quit unless alive && :close != @state - @env.clear @hp.reset @state = :headers disable if enabled? @@ -131,7 +130,7 @@ module Rainbows when :close close if @_write_buffer.empty? when :headers - if @hp.headers(@env, @buf) + if @hp.parse app_call else unless enabled? diff --git a/lib/rainbows/rev/thread.rb b/lib/rainbows/rev/thread.rb index 7b7d455..2356ae2 100644 --- a/lib/rainbows/rev/thread.rb +++ b/lib/rainbows/rev/thread.rb @@ -24,7 +24,6 @@ module Rainbows rev_write_response(response, alive) return quit unless alive && :close != @state - @env.clear @hp.reset @state = :headers end -- cgit v1.2.3-24-ge0c7