From d4a2b5dd2b85f4b2d3bb120ee1e1b0dde31bc25c Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Wed, 20 Oct 2010 17:48:58 -0700 Subject: unicorn 2.x updates + kgio We get basic internal API changes from Unicorn, code simplifications coming next. --- lib/rainbows/fiber/rev.rb | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) (limited to 'lib/rainbows/fiber/rev.rb') diff --git a/lib/rainbows/fiber/rev.rb b/lib/rainbows/fiber/rev.rb index 2c1abb7..6969f5b 100644 --- a/lib/rainbows/fiber/rev.rb +++ b/lib/rainbows/fiber/rev.rb @@ -78,16 +78,17 @@ module Rainbows::Fiber def process(io) G.cur += 1 client = FIO.new(io, ::Fiber.current) - buf = client.read_timeout or return hp = HttpParser.new - env = {} + client.readpartial(16384, buf = hp.buf) begin # loop - buf << (client.read_timeout or return) until hp.headers(env, buf) + until env = hp.parse + buf << (client.read_timeout or return) + end env[CLIENT_IO] = client env[RACK_INPUT] = 0 == hp.content_length ? - HttpRequest::NULL_IO : TeeInput.new(client, env, hp, buf) + HttpRequest::NULL_IO : TeeInput.new(client, hp) env[REMOTE_ADDR] = io.kgio_addr status, headers, body = APP.call(env.update(RACK_DEFAULTS)) @@ -100,16 +101,12 @@ module Rainbows::Fiber if hp.headers? headers = HH.new(headers) range = make_range!(env, status, headers) and status = range.shift - headers[CONNECTION] = if hp.keepalive? && G.alive - KEEP_ALIVE - else - env = false - CLOSE - end + env = hp.keepalive? && G.alive + headers[CONNECTION] = env ? KEEP_ALIVE : CLOSE client.write(response_header(status, headers)) end write_body(client, body, range) - end while env && env.clear && hp.reset.nil? + end while env && hp.reset.nil? rescue => e Error.write(io, e) ensure -- cgit v1.2.3-24-ge0c7