about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorzedshaw <zedshaw@19e92222-5c0b-0410-8929-a290d50e31e9>2006-09-03 19:47:53 +0000
committerzedshaw <zedshaw@19e92222-5c0b-0410-8929-a290d50e31e9>2006-09-03 19:47:53 +0000
commit17a3d3d4a9a56a55c18f39518134701a92f9a2a8 (patch)
tree67a4626be1e14546fc3909c8c41d61997e57bf50
parent60364dd75416e42e090917eabe77993117a07abb (diff)
downloadunicorn-17a3d3d4a9a56a55c18f39518134701a92f9a2a8.tar.gz
git-svn-id: svn+ssh://rubyforge.org/var/svn/mongrel/trunk@341 19e92222-5c0b-0410-8929-a290d50e31e9
-rw-r--r--lib/mongrel.rb21
-rw-r--r--lib/mongrel/handlers.rb2
-rw-r--r--lib/mongrel/rails.rb12
3 files changed, 20 insertions, 15 deletions
diff --git a/lib/mongrel.rb b/lib/mongrel.rb
index 8d0c57c..c0f07ab 100644
--- a/lib/mongrel.rb
+++ b/lib/mongrel.rb
@@ -432,18 +432,21 @@ module Mongrel
     # reading and written in chunks to the socket.
     #
     # Sendfile API support has been removed in 0.3.13.4 due to stability problems.
-    def send_file(path)
-      File.open(path, "rb") do |f|
-        while chunk = f.read(Const::CHUNK_SIZE) and chunk.length > 0
-          begin
-            write(chunk)
-          rescue Object => exc
-            # TODO: find out if people care about failures to write these files
-            break
+    def send_file(path, small_file = false)
+      if small_file
+        File.open(path, "rb") {|f| @socket << f.read }
+      else
+        File.open(path, "rb") do |f|
+          while chunk = f.read(Const::CHUNK_SIZE) and chunk.length > 0
+            begin
+              write(chunk)
+            rescue Object => exc
+              break
+            end
           end
         end
-        @body_sent = true
       end
+      @body_sent = true
     end
 
     def socket_error(details)
diff --git a/lib/mongrel/handlers.rb b/lib/mongrel/handlers.rb
index 3bf8d08..4d36e8b 100644
--- a/lib/mongrel/handlers.rb
+++ b/lib/mongrel/handlers.rb
@@ -234,7 +234,7 @@ module Mongrel
         response.send_header
 
         if not header_only
-          response.send_file(req_path)
+          response.send_file(req_path, stat.size < Const::CHUNK_SIZE * 2)
         end
       end
     end
diff --git a/lib/mongrel/rails.rb b/lib/mongrel/rails.rb
index 5dcbf7f..ca430d5 100644
--- a/lib/mongrel/rails.rb
+++ b/lib/mongrel/rails.rb
@@ -56,7 +56,9 @@ module Mongrel
       # * If it exists at PATH_INFO+".html" exists then serve that.
       # * Finally, construct a Mongrel::CGIWrapper and run Dispatcher.dispatch to have Rails go.
       def process(request, response)
-        return if response.socket.closed?
+        if response.socket.closed?
+          return
+        end
 
         path_info = request.params[Mongrel::Const::PATH_INFO]
         page_cached = path_info + ".html"
@@ -66,7 +68,7 @@ module Mongrel
           # File exists as-is so serve it up
           @files.process(request,response)
         elsif get_or_head and @files.can_serve(page_cached)
-          # possible cached page, serve it up      
+          # possible cached page, serve it up
           request.params[Mongrel::Const::PATH_INFO] = page_cached
           @files.process(request,response)
         else
@@ -76,7 +78,7 @@ module Mongrel
             # we don't want the output to be really final until we're out of the lock
             cgi.default_really_final = false
 
-            log_threads_waiting_for(request.params["PATH_INFO"])
+            log_threads_waiting_for(request.params["PATH_INFO"]) if $mongrel_debug_client
 
             @guard.synchronize(:EX) {
               Dispatcher.dispatch(cgi, ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS, response.body)
@@ -85,7 +87,7 @@ module Mongrel
             # This finalizes the output using the proper HttpResponse way
             cgi.out("text/html",true) {""}
           rescue Errno::EPIPE
-            # ignored
+            response.socket.close
           rescue Object => rails_error
             STDERR.puts "#{Time.now}: Error calling Dispatcher.dispatch #{rails_error.inspect}"
             STDERR.puts rails_error.backtrace.join("\n")
@@ -94,7 +96,7 @@ module Mongrel
       end
 
       def log_threads_waiting_for(event)
-        if $mongrel_debug_client and (Time.now - @tick > 10)
+        if Time.now - @tick > 10
           STDERR.puts "#{Time.now}: #{@guard.sync_waiting.length} threads sync_waiting for #{event}, #{self.listener.workers.list.length} still active in mongrel."
           @tick = Time.now
         end