about summary refs log tree commit homepage
path: root/lib/unicorn/app
diff options
context:
space:
mode:
Diffstat (limited to 'lib/unicorn/app')
-rw-r--r--lib/unicorn/app/exec_cgi.rb48
-rw-r--r--lib/unicorn/app/inetd.rb5
-rw-r--r--lib/unicorn/app/old_rails.rb1
-rw-r--r--lib/unicorn/app/old_rails/static.rb2
4 files changed, 29 insertions, 27 deletions
diff --git a/lib/unicorn/app/exec_cgi.rb b/lib/unicorn/app/exec_cgi.rb
index ff5f53a..232b681 100644
--- a/lib/unicorn/app/exec_cgi.rb
+++ b/lib/unicorn/app/exec_cgi.rb
@@ -1,5 +1,5 @@
 # -*- encoding: binary -*-
-
+# :enddoc:
 require 'unicorn'
 
 module Unicorn::App
@@ -28,6 +28,24 @@ module Unicorn::App
       SERVER_SOFTWARE
     ).map { |x| x.freeze } # frozen strings are faster for Hash assignments
 
+    class Body < Unicorn::TmpIO
+      def body_offset=(n)
+        sysseek(@body_offset = n)
+      end
+
+      def each
+        sysseek @body_offset
+        # don't use a preallocated buffer for sysread since we can't
+        # guarantee an actual socket is consuming the yielded string
+        # (or if somebody is pushing to an array for eventual concatenation
+        begin
+          yield sysread(CHUNK_SIZE)
+        rescue EOFError
+          break
+        end while true
+      end
+    end
+
     # Intializes the app, example of usage in a config.ru
     #   map "/cgit" do
     #     run Unicorn::App::ExecCgi.new("/path/to/cgit.cgi")
@@ -43,7 +61,7 @@ module Unicorn::App
 
     # Calls the app
     def call(env)
-      out, err = Unicorn::Util.tmpio, Unicorn::Util.tmpio
+      out, err = Body.new, Unicorn::TmpIO.new
       inp = force_file_input(env)
       pid = fork { run_child(inp, out, err, env) }
       inp.close
@@ -67,9 +85,9 @@ module Unicorn::App
       ENV['GATEWAY_INTERFACE'] = 'CGI/1.1'
       env.keys.grep(/^HTTP_/) { |key| ENV[key] = env[key] }
 
-      a = IO.new(0).reopen(inp)
-      b = IO.new(1).reopen(out)
-      c = IO.new(2).reopen(err)
+      $stdin.reopen(inp)
+      $stdout.reopen(out)
+      $stderr.reopen(err)
       exec(*args)
     end
 
@@ -87,23 +105,7 @@ module Unicorn::App
         offset = 4
       end
       offset += head.length
-
-      # Allows +out+ to be used as a Rack body.
-      out.instance_eval { class << self; self; end }.instance_eval {
-        define_method(:each) { |&blk|
-          sysseek(offset)
-
-          # don't use a preallocated buffer for sysread since we can't
-          # guarantee an actual socket is consuming the yielded string
-          # (or if somebody is pushing to an array for eventual concatenation
-          begin
-            blk.call(sysread(CHUNK_SIZE))
-          rescue EOFError
-            break
-          end while true
-        }
-      }
-
+      out.body_offset = offset
       size -= offset
       prev = nil
       headers = Rack::Utils::HeaderHash.new
@@ -125,7 +127,7 @@ module Unicorn::App
       if inp.respond_to?(:size) && inp.size == 0
         ::File.open('/dev/null', 'rb')
       else
-        tmp = Unicorn::Util.tmpio
+        tmp = Unicorn::TmpIO.new
 
         buf = inp.read(CHUNK_SIZE)
         begin
diff --git a/lib/unicorn/app/inetd.rb b/lib/unicorn/app/inetd.rb
index 9bfa7cb..2a212a2 100644
--- a/lib/unicorn/app/inetd.rb
+++ b/lib/unicorn/app/inetd.rb
@@ -1,10 +1,9 @@
 # -*- encoding: binary -*-
-
+# :enddoc:
 # Copyright (c) 2009 Eric Wong
 # You can redistribute it and/or modify it under the same terms as Ruby.
 
 # this class *must* be used with Rack::Chunked
-
 module Unicorn::App
   class Inetd < Struct.new(:cmd)
 
@@ -47,7 +46,7 @@ module Unicorn::App
         }
       end
 
-      def each(&block)
+      def each
         begin
           rd, = IO.select([err_rd, out_rd])
           rd && rd.first or next
diff --git a/lib/unicorn/app/old_rails.rb b/lib/unicorn/app/old_rails.rb
index e674d78..5f04ce7 100644
--- a/lib/unicorn/app/old_rails.rb
+++ b/lib/unicorn/app/old_rails.rb
@@ -1,5 +1,6 @@
 # -*- encoding: binary -*-
 
+# :enddoc:
 # This code is based on the original Rails handler in Mongrel
 # Copyright (c) 2005 Zed A. Shaw
 # Copyright (c) 2009 Eric Wong
diff --git a/lib/unicorn/app/old_rails/static.rb b/lib/unicorn/app/old_rails/static.rb
index 13a435e..1d53717 100644
--- a/lib/unicorn/app/old_rails/static.rb
+++ b/lib/unicorn/app/old_rails/static.rb
@@ -1,5 +1,5 @@
 # -*- encoding: binary -*-
-
+# :enddoc:
 # This code is based on the original Rails handler in Mongrel
 # Copyright (c) 2005 Zed A. Shaw
 # Copyright (c) 2009 Eric Wong