about summary refs log tree commit homepage
path: root/lib/rainbows/base.rb
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2010-10-21 16:25:39 -0700
committerEric Wong <normalperson@yhbt.net>2010-10-22 18:37:45 +0000
commit15631717fce044fbad2f386a7b1c7daf4bdd83d2 (patch)
treef32c80aafb8b5fe13fefe9a1e3765dd757ccde7d /lib/rainbows/base.rb
parentd4a2b5dd2b85f4b2d3bb120ee1e1b0dde31bc25c (diff)
downloadrainbows-15631717fce044fbad2f386a7b1c7daf4bdd83d2.tar.gz
Despite the large number of changes, most of it is code
movement here.
Diffstat (limited to 'lib/rainbows/base.rb')
-rw-r--r--lib/rainbows/base.rb56
1 files changed, 2 insertions, 54 deletions
diff --git a/lib/rainbows/base.rb b/lib/rainbows/base.rb
index fe2cf31..3027aba 100644
--- a/lib/rainbows/base.rb
+++ b/lib/rainbows/base.rb
@@ -8,14 +8,10 @@
 module Rainbows::Base
 
   # :stopdoc:
-  include Rainbows::Const
-  include Rainbows::Response
+  include Rainbows::ProcessClient
 
   # shortcuts...
   G = Rainbows::G
-  NULL_IO = Unicorn::HttpRequest::NULL_IO
-  TeeInput = Rainbows::TeeInput
-  HttpParser = Unicorn::HttpParser
 
   # this method is called by all current concurrency models
   def init_worker_process(worker) # :nodoc:
@@ -33,58 +29,10 @@ module Rainbows::Base
     trap(:USR1) { reopen_worker_logs(worker.nr) }
     trap(:QUIT) { G.quit! }
     [:TERM, :INT].each { |sig| trap(sig) { exit!(0) } } # instant shutdown
+    Rainbows::ProcessClient.const_set(:APP, G.server.app)
     logger.info "Rainbows! #@use worker_connections=#@worker_connections"
   end
 
-  def wait_headers_readable(client)  # :nodoc:
-    IO.select([client], nil, nil, G.kato)
-  end
-
-  # once a client is accepted, it is processed in its entirety here
-  # in 3 easy steps: read request, call app, write app response
-  # this is used by synchronous concurrency models
-  #   Base, ThreadSpawn, ThreadPool
-  def process_client(client) # :nodoc:
-    hp = HttpParser.new
-    client.readpartial(CHUNK_SIZE, buf = hp.buf)
-    remote_addr = Rainbows.addr(client)
-
-    begin # loop
-      until env = hp.parse
-        wait_headers_readable(client) or return
-        buf << client.readpartial(CHUNK_SIZE)
-      end
-
-      env[CLIENT_IO] = client
-      env[RACK_INPUT] = 0 == hp.content_length ? NULL_IO : TeeInput.new(client, hp)
-      env[REMOTE_ADDR] = remote_addr
-      status, headers, body = app.call(env.update(RACK_DEFAULTS))
-
-      if 100 == status.to_i
-        client.write(EXPECT_100_RESPONSE)
-        env.delete(HTTP_EXPECT)
-        status, headers, body = app.call(env)
-      end
-
-      if hp.headers?
-        headers = HH.new(headers)
-        range = make_range!(env, status, headers) and status = range.shift
-        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 && hp.reset.nil?
-  # if we get any error, try to write something back to the client
-  # assuming we haven't closed the socket, but don't get hung up
-  # if the socket is already closed or broken.  We'll always ensure
-  # the socket is closed at the end of this function
-  rescue => e
-    Rainbows::Error.write(client, e)
-  ensure
-    client.close unless client.closed?
-  end
-
   def self.included(klass) # :nodoc:
     klass.const_set :LISTENERS, Rainbows::HttpServer::LISTENERS
     klass.const_set :G, Rainbows::G