about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2010-12-30 08:32:26 +0000
committerEric Wong <normalperson@yhbt.net>2011-01-04 16:21:17 -0800
commitc38bc88363d4c4f5f639540ca86f4dd1225df79e (patch)
tree97d039d48177dc571d81a224437dffc7d44045de
parent1a03f9a525faf4c997546c419de6854223b645c4 (diff)
downloadrainbows-c38bc88363d4c4f5f639540ca86f4dd1225df79e.tar.gz
Unique method names makes it easier to follow code and determine
where our methods come from.
-rw-r--r--lib/rainbows/fiber/body.rb3
-rw-r--r--lib/rainbows/response/body.rb25
-rw-r--r--lib/rainbows/revactor/body.rb3
3 files changed, 14 insertions, 17 deletions
diff --git a/lib/rainbows/fiber/body.rb b/lib/rainbows/fiber/body.rb
index 29926c6..1d7d325 100644
--- a/lib/rainbows/fiber/body.rb
+++ b/lib/rainbows/fiber/body.rb
@@ -12,7 +12,7 @@ module Rainbows::Fiber::Body # :nodoc:
 
   # the sendfile 1.0.0+ gem includes IO#sendfile_nonblock
   if IO.method_defined?(:sendfile_nonblock)
-    def write_body_file(client, body, range)
+    def write_body_file_sendfile_fiber(client, body, range)
       sock, n, body = client.to_io, nil, body_to_io(body)
       offset, count = range ? range : [ 0, body.stat.size ]
       begin
@@ -26,6 +26,7 @@ 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
diff --git a/lib/rainbows/response/body.rb b/lib/rainbows/response/body.rb
index e80217d..a5d04dd 100644
--- a/lib/rainbows/response/body.rb
+++ b/lib/rainbows/response/body.rb
@@ -58,26 +58,28 @@ module Rainbows::Response::Body # :nodoc:
   end
 
   if IO.method_defined?(:sendfile_nonblock)
-    def write_body_file(sock, body, range)
+    def write_body_file_sendfile(sock, body, range)
       io = body_to_io(body)
       range ? sock.sendfile(io, range[0], range[1]) : sock.sendfile(io, 0)
       ensure
         close_if_private(io)
     end
+    ALIASES[:write_body_file] = :write_body_file_sendfile
   end
 
   if IO.respond_to?(:copy_stream)
-    unless method_defined?(:write_body_file)
+    unless method_defined?(:write_body_file_sendfile)
       # try to use sendfile() via IO.copy_stream, otherwise pread()+write()
-      def write_body_file(sock, body, range)
+      def write_body_file_copy_stream(sock, body, range)
         range ? IO.copy_stream(body, sock, range[1], range[0]) :
                 IO.copy_stream(body, sock, nil, 0)
       end
+      ALIASES[:write_body_file] = :write_body_file_copy_stream
     end
 
     # only used when body is a pipe or socket that can't handle
     # pread() semantics
-    def write_body_stream(sock, body, range)
+    def write_body_stream(sock, body)
       IO.copy_stream(body, sock)
     end
   else
@@ -85,18 +87,11 @@ module Rainbows::Response::Body # :nodoc:
     ALIASES[:write_body_stream] = :write_body_each
   end
 
-  if method_defined?(:write_body_file)
+  if ALIASES[:write_body_file]
     # middlewares/apps may return with a body that responds to +to_path+
     def write_body_path(sock, body, range)
-      stat = File.stat(body.to_path)
-      stat.file? ? write_body_file(sock, body, range) :
-                   write_body_stream(sock, body, range)
-      ensure
-        body.respond_to?(:close) and body.close
-    end
-  elsif method_defined?(:write_body_stream)
-    def write_body_path(sock, body, range)
-      write_body_stream(sock, body, range)
+      File.file?(body.to_path) ? write_body_file(sock, body, range) :
+                                 write_body_stream(sock, body)
       ensure
         body.respond_to?(:close) and body.close
     end
@@ -106,7 +101,7 @@ module Rainbows::Response::Body # :nodoc:
     def write_body(client, body, range)
       body.respond_to?(:to_path) ?
         write_body_path(client, body, range) :
-        write_body_each(client, body, range)
+        write_body_each(client, body)
     end
   else
     ALIASES[:write_body] = :write_body_each
diff --git a/lib/rainbows/revactor/body.rb b/lib/rainbows/revactor/body.rb
index 7bfb5de..9820df3 100644
--- a/lib/rainbows/revactor/body.rb
+++ b/lib/rainbows/revactor/body.rb
@@ -7,7 +7,7 @@ module Rainbows::Revactor::Body
   }
 
   if IO.method_defined?(:sendfile_nonblock)
-    def write_body_file(client, body, range)
+    def write_body_file_sendfile_revactor(client, body, range)
       body = body_to_io(body)
       sock = client.instance_variable_get(:@_io)
       pfx = Revactor::TCP::Socket === client ? :tcp : :unix
@@ -33,6 +33,7 @@ module Rainbows::Revactor::Body
       ensure
         close_if_private(body)
     end
+    ALIASES[:write_body_file] = :write_body_file_sendfile_revactor
   else
     ALIASES[:write_body] = :write_body_each
   end