about summary refs log tree commit homepage
path: root/lib/rainbows/fiber
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2010-12-30 08:33:15 +0000
committerEric Wong <normalperson@yhbt.net>2011-01-04 16:37:42 -0800
commite21939d776673b2f8887adf7a5c64812b7d2e98e (patch)
tree48aa3a71201e770758bd09b325c3f2704411af7f /lib/rainbows/fiber
parent4a76da1833922c74e147be5def9bfe04fd0c16a2 (diff)
downloadrainbows-e21939d776673b2f8887adf7a5c64812b7d2e98e.tar.gz
Rack::Utils::HeaderHash is still very expensive in Rack 1.2,
especially for simple things that we want to run as fast as
possible with minimal interference.  HeaderHash is unnecessary
for most requests that do not send Content-Range in responses.
Diffstat (limited to 'lib/rainbows/fiber')
-rw-r--r--lib/rainbows/fiber/base.rb4
-rw-r--r--lib/rainbows/fiber/body.rb18
-rw-r--r--lib/rainbows/fiber/coolio/server.rb3
3 files changed, 7 insertions, 18 deletions
diff --git a/lib/rainbows/fiber/base.rb b/lib/rainbows/fiber/base.rb
index b693451..ae885b6 100644
--- a/lib/rainbows/fiber/base.rb
+++ b/lib/rainbows/fiber/base.rb
@@ -57,7 +57,7 @@ module Rainbows::Fiber::Base
 
   def process(client)
     G.cur += 1
-    process_client(client)
+    client.process_loop
   ensure
     G.cur -= 1
     ZZ.delete(client.f)
@@ -65,7 +65,7 @@ module Rainbows::Fiber::Base
 
   def self.setup(klass, app)
     require 'rainbows/fiber/body'
-    klass.__send__(:include, Rainbows::Fiber::Body)
+    Rainbows::Client.__send__(:include, Rainbows::Fiber::Body)
     self.const_set(:APP, app)
   end
 end
diff --git a/lib/rainbows/fiber/body.rb b/lib/rainbows/fiber/body.rb
index 1d7d325..872b1df 100644
--- a/lib/rainbows/fiber/body.rb
+++ b/lib/rainbows/fiber/body.rb
@@ -5,20 +5,15 @@
 # this is meant to be included _after_ Rainbows::Response::Body
 module Rainbows::Fiber::Body # :nodoc:
 
-  # TODO non-blocking splice(2) under Linux
-  ALIASES = {
-    :write_body_stream => :write_body_each
-  }
-
   # the sendfile 1.0.0+ gem includes IO#sendfile_nonblock
   if IO.method_defined?(:sendfile_nonblock)
-    def write_body_file_sendfile_fiber(client, body, range)
-      sock, n, body = client.to_io, nil, body_to_io(body)
+    def write_body_file(body, range)
+      sock, n, body = to_io, nil, body_to_io(body)
       offset, count = range ? range : [ 0, body.stat.size ]
       begin
         offset += (n = sock.sendfile_nonblock(body, offset, count))
       rescue Errno::EAGAIN
-        client.kgio_wait_writable
+        kgio_wait_writable
         retry
       rescue EOFError
         break
@@ -26,14 +21,9 @@ module Rainbows::Fiber::Body # :nodoc:
       ensure
         close_if_private(body)
     end
-    ALIASES[:write_body_file] = :write_body_file_sendfile_fiber
-  else
-    ALIASES[:write_body] = :write_body_each
   end
 
   def self.included(klass)
-    ALIASES.each do |new_method, orig_method|
-      klass.__send__(:alias_method, new_method, orig_method)
-    end
+    klass.__send__ :alias_method, :write_body_stream, :write_body_each
   end
 end
diff --git a/lib/rainbows/fiber/coolio/server.rb b/lib/rainbows/fiber/coolio/server.rb
index 0de1ab3..b064953 100644
--- a/lib/rainbows/fiber/coolio/server.rb
+++ b/lib/rainbows/fiber/coolio/server.rb
@@ -2,7 +2,6 @@
 # :enddoc:
 class Rainbows::Fiber::Coolio::Server < Coolio::IOWatcher
   G = Rainbows::G
-  include Rainbows::ProcessClient
 
   def to_io
     @io
@@ -25,7 +24,7 @@ class Rainbows::Fiber::Coolio::Server < Coolio::IOWatcher
 
   def process(io)
     G.cur += 1
-    process_client(io)
+    io.process_loop
   ensure
     G.cur -= 1
   end