about summary refs log tree commit homepage
path: root/lib/rainbows/revactor.rb
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2009-11-18 00:08:20 -0800
committerEric Wong <normalperson@yhbt.net>2009-11-18 00:08:20 -0800
commitfc931be708f8da823a484fe88da9251d9cc72949 (patch)
tree6b8196c01592dd0057eb97abdcc573a0f21c395b /lib/rainbows/revactor.rb
parent85f56d09ae9d9c2e2a28502312f2f3e5ec655693 (diff)
downloadrainbows-fc931be708f8da823a484fe88da9251d9cc72949.tar.gz
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
Diffstat (limited to 'lib/rainbows/revactor.rb')
-rw-r--r--lib/rainbows/revactor.rb17
1 files changed, 13 insertions, 4 deletions
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