8 $stderr.puts
"listener: #{s}" if ENV && ENV["DEBUG_GATEWAY"]
12 attr_accessor
:stdinput, :stdoutput, :env_table
13 def initialize(env_table
, input
= nil, output
= nil)
14 self.env_table
= env_table
15 self.stdinput
= input
|| StringIO
.new
16 self.stdoutput
= output
|| StringIO
.new
20 def out(stream
) # Ignore the requested output stream
28 def initialize(timeout
, socket_path
)
29 @socket = File
.expand_path(socket_path
)
34 @handler = RailsFCGIHandler
.new
35 @handler.extend DRbUndumped
37 message
'opening socket'
38 DRb
.start_service("drbunix:#{@socket}", self)
40 message
'entering process loop'
41 @handler.process
! self
44 def each_cgi(&cgi_block
)
45 @cgi_block = cgi_block
46 message
'entering idle loop'
48 sleep
@timeout rescue nil
54 def process(env, input
)
55 message
'received request'
59 message
'creating input stream'
60 input_stream
= StringIO
.new(input
)
61 message
'building CGI instance'
62 cgi
= RemoteCGI
.new(eval(env), input_stream
)
64 message
'yielding to fcgi handler'
66 message
'yield finished -- sending output'
69 output
= cgi
.stdoutput
.read
76 message
'shutting down'
78 FileUtils
.rm_f
@socket
83 socket_path
= ARGV.shift
84 timeout
= (ARGV.shift
|| 90).to_i
86 Listener
.new(timeout
, socket_path
)