Parent

Included Modules

Class/Module Index [+]

Quicksearch

Listener

Public Class Methods

new(timeout, socket_path) click to toggle source
# File lib/commands/ncgi/listener, line 28
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

Public Instance Methods

die!() click to toggle source
# File lib/commands/ncgi/listener, line 75
def die!
  message 'shutting down'
  DRb.stop_service
  FileUtils.rm_f @socket
  Kernel.exit 0
end
each_cgi(&cgi_block) click to toggle source
# File lib/commands/ncgi/listener, line 44
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
process(env, input) click to toggle source
# File lib/commands/ncgi/listener, line 54
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

[Validate]

Generated with the Darkfish Rdoc Generator 2.