diff options
author | Joshua Peek <josh@joshpeek.com> | 2009-10-05 11:16:24 -0500 |
---|---|---|
committer | Joshua Peek <josh@joshpeek.com> | 2009-10-05 11:16:24 -0500 |
commit | 570f055c44a0b6da973f63689f8fedbef9fe32d3 (patch) | |
tree | 72d59dbe672653fefcdabda37c24bcb5b80b2b98 /railties/lib/rails/commands/ncgi/listener | |
parent | 20d6938453f439531a13e2ef1fd0905edf56294c (diff) | |
download | rails-570f055c44a0b6da973f63689f8fedbef9fe32d3.tar.gz rails-570f055c44a0b6da973f63689f8fedbef9fe32d3.tar.bz2 rails-570f055c44a0b6da973f63689f8fedbef9fe32d3.zip |
Yank FCGI Handler from core
http://github.com/rails/fcgi_handler
Diffstat (limited to 'railties/lib/rails/commands/ncgi/listener')
-rwxr-xr-x | railties/lib/rails/commands/ncgi/listener | 86 |
1 files changed, 0 insertions, 86 deletions
diff --git a/railties/lib/rails/commands/ncgi/listener b/railties/lib/rails/commands/ncgi/listener deleted file mode 100755 index 7079ef78a6..0000000000 --- a/railties/lib/rails/commands/ncgi/listener +++ /dev/null @@ -1,86 +0,0 @@ -#!/usr/bin/env ruby - -require 'stringio' -require 'fileutils' -require 'fcgi_handler' - -def message(s) - $stderr.puts "listener: #{s}" if ENV && ENV["DEBUG_GATEWAY"] -end - -class RemoteCGI < CGI - attr_accessor :stdinput, :stdoutput, :env_table - def initialize(env_table, input = nil, output = nil) - self.env_table = env_table - self.stdinput = input || StringIO.new - self.stdoutput = output || StringIO.new - super() - end - - def out(stream) # Ignore the requested output stream - super(stdoutput) - end -end - -class Listener - include DRbUndumped - - def initialize(timeout, socket_path) - @socket = File.expand_path(socket_path) - @mutex = Mutex.new - @active = false - @timeout = timeout - - @handler = RailsFCGIHandler.new - @handler.extend DRbUndumped - - message 'opening socket' - DRb.start_service("drbunix:#{@socket}", self) - - message 'entering process loop' - @handler.process! self - end - - def each_cgi(&cgi_block) - @cgi_block = cgi_block - message 'entering idle loop' - loop do - sleep @timeout rescue nil - die! unless @active - @active = false - end - end - - def process(env, input) - message 'received request' - @mutex.synchronize do - @active = true - - message 'creating input stream' - input_stream = StringIO.new(input) - message 'building CGI instance' - cgi = RemoteCGI.new(eval(env), input_stream) - - message 'yielding to fcgi handler' - @cgi_block.call cgi - message 'yield finished -- sending output' - - cgi.stdoutput.seek(0) - output = cgi.stdoutput.read - - return output - end - end - - def die! - message 'shutting down' - DRb.stop_service - FileUtils.rm_f @socket - Kernel.exit 0 - end -end - -socket_path = ARGV.shift -timeout = (ARGV.shift || 90).to_i - -Listener.new(timeout, socket_path) |