1 # -*- encoding: binary -*-
4 require 'rainbows/rev/master'
6 RUBY_VERSION =~ %r{\A1\.8} && Rev::VERSION < "0.3.2" and
7 warn "Rev (< 0.3.2) and Threads do not mix well under Ruby 1.8"
12 class ThreadClient < Client
17 @env[RACK_INPUT] = @input
18 app_dispatch # must be implemented by subclass
21 # this is only called in the master thread
22 def response_write(response)
24 alive = @hp.keepalive? && G.alive
25 rev_write_response(response, alive)
26 return quit unless alive
31 # keepalive requests are always body-less, so @input is unchanged
32 if @hp.headers(@env, @buf)
33 @input = HttpRequest::NULL_IO
40 # fails-safe application dispatch, we absolutely cannot
41 # afford to fail or raise an exception (killing the thread)
42 # here because that could cause a deadlock and we'd leak FDs
45 @env[REMOTE_ADDR] = @remote_addr
46 APP.call(@env.update(RACK_DEFAULTS))
48 Error.app(e) # we guarantee this does not raise