From fc931be708f8da823a484fe88da9251d9cc72949 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Wed, 18 Nov 2009 00:08:20 -0800 Subject: revactor: :timeout for reading headers in TCP sockets We'll be getting a keepalive_timeout setting soon, clients with 300 second idle keepalives are ridiculous and Ruby objects are still not that cheap in 1.9 --- lib/rainbows/revactor.rb | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'lib/rainbows/revactor.rb') diff --git a/lib/rainbows/revactor.rb b/lib/rainbows/revactor.rb index 43dc60d..4cf6f11 100644 --- a/lib/rainbows/revactor.rb +++ b/lib/rainbows/revactor.rb @@ -23,21 +23,28 @@ module Rainbows module Revactor require 'rainbows/revactor/tee_input' + RD_ARGS = { :timeout => 5 } + include Base # once a client is accepted, it is processed in its entirety here # in 3 easy steps: read request, call app, write app response def process_client(client) - buf = client.read or return # this probably does not happen... + rd_args = [ nil ] + remote_addr = if ::Revactor::TCP::Socket === client + rd_args << RD_ARGS + client.remote_addr + else + LOCALHOST + end + buf = client.read(*rd_args) hp = HttpParser.new env = {} alive = true - remote_addr = ::Revactor::TCP::Socket === client ? - client.remote_addr : LOCALHOST begin while ! hp.headers(env, buf) - buf << client.read + buf << client.read(*rd_args) end env[Const::RACK_INPUT] = 0 == hp.content_length ? @@ -57,6 +64,8 @@ module Rainbows HttpResponse.write(client, response, out) end while alive and hp.reset.nil? and env.clear client.close + rescue ::Revactor::TCP::ReadError + client.close rescue => e handle_error(client, e) end -- cgit v1.2.3-24-ge0c7