about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2010-10-25 22:15:47 +0000
committerEric Wong <normalperson@yhbt.net>2010-10-25 22:15:47 +0000
commit894cb73887c106acc793f0317ee849ae215ead56 (patch)
tree9f4f4d8caff831383a46dc4eb05e71b32c6ee628
parent4ee6e0dafeb1b7af28fa90ae27c1a1a04aa8e852 (diff)
downloadrainbows-894cb73887c106acc793f0317ee849ae215ead56.tar.gz
kgio_trywrite is superior if it is available.
-rw-r--r--lib/rainbows/error.rb8
-rw-r--r--lib/rainbows/process_client.rb4
-rw-r--r--lib/rainbows/rev/client.rb2
-rw-r--r--lib/rainbows/writer_thread_pool.rb8
-rw-r--r--lib/rainbows/writer_thread_spawn.rb8
5 files changed, 14 insertions, 16 deletions
diff --git a/lib/rainbows/error.rb b/lib/rainbows/error.rb
index bdbfdc5..68cdec4 100644
--- a/lib/rainbows/error.rb
+++ b/lib/rainbows/error.rb
@@ -9,7 +9,13 @@ module Rainbows::Error
   # if the socket is already closed or broken.  We'll always ensure
   # the socket is closed at the end of this function
   def self.write(io, e)
-    msg = response(e) and io.write_nonblock(msg)
+    if msg = response(e)
+      if io.respond_to?(:kgio_trywrite)
+        io.kgio_trywrite(msg)
+      else
+        io.write_nonblock(msg)
+      end
+    end
     rescue
   end
 
diff --git a/lib/rainbows/process_client.rb b/lib/rainbows/process_client.rb
index 5e200e5..1e2d0d9 100644
--- a/lib/rainbows/process_client.rb
+++ b/lib/rainbows/process_client.rb
@@ -19,13 +19,13 @@ module Rainbows::ProcessClient
   #   Base, ThreadSpawn, ThreadPool
   def process_client(client) # :nodoc:
     hp = HttpParser.new
-    client.readpartial(16384, buf = hp.buf)
+    client.kgio_read!(16384, buf = hp.buf)
     remote_addr = client.kgio_addr
 
     begin # loop
       until env = hp.parse
         wait_headers_readable(client) or return
-        buf << client.readpartial(16384)
+        buf << client.kgio_read!(16384)
       end
 
       env[CLIENT_IO] = client
diff --git a/lib/rainbows/rev/client.rb b/lib/rainbows/rev/client.rb
index 0c02525..20adbc1 100644
--- a/lib/rainbows/rev/client.rb
+++ b/lib/rainbows/rev/client.rb
@@ -147,7 +147,7 @@ module Rainbows
       def handle_error(e)
         close_deferred
         if msg = Error.response(e)
-          @_io.write_nonblock(msg) rescue nil
+          @_io.kgio_trywrite(msg) rescue nil
         end
         @_write_buffer.clear
         ensure
diff --git a/lib/rainbows/writer_thread_pool.rb b/lib/rainbows/writer_thread_pool.rb
index 335a901..a8ffd7d 100644
--- a/lib/rainbows/writer_thread_pool.rb
+++ b/lib/rainbows/writer_thread_pool.rb
@@ -29,10 +29,6 @@ module Rainbows
         to_io.kgio_addr
       end
 
-      def readpartial(size, buf = "")
-        to_io.readpartial(size, buf)
-      end
-
       def kgio_read(size, buf = "")
         to_io.kgio_read(size, buf)
       end
@@ -41,8 +37,8 @@ module Rainbows
         to_io.kgio_read!(size, buf)
       end
 
-      def write_nonblock(buf)
-        to_io.write_nonblock(buf)
+      def kgio_trywrite(buf)
+        to_io.kgio_trywrite(buf)
       end
 
       def write(buf)
diff --git a/lib/rainbows/writer_thread_spawn.rb b/lib/rainbows/writer_thread_spawn.rb
index 6468151..c190f89 100644
--- a/lib/rainbows/writer_thread_spawn.rb
+++ b/lib/rainbows/writer_thread_spawn.rb
@@ -34,10 +34,6 @@ module Rainbows
         to_io.kgio_addr
       end
 
-      def readpartial(size, buf = "")
-        to_io.readpartial(size, buf)
-      end
-
       def kgio_read(size, buf = "")
         to_io.kgio_read(size, buf)
       end
@@ -46,8 +42,8 @@ module Rainbows
         to_io.kgio_read!(size, buf)
       end
 
-      def write_nonblock(buf)
-        to_io.write_nonblock(buf)
+      def kgio_trywrite(buf)
+        to_io.kgio_trywrite(buf)
       end
 
       def queue_writer