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)
23 alive = @hp.next? && G.alive
24 rev_write_response(response, alive)
25 return quit unless alive && :close != @state
30 # fails-safe application dispatch, we absolutely cannot
31 # afford to fail or raise an exception (killing the thread)
32 # here because that could cause a deadlock and we'd leak FDs
35 @env[REMOTE_ADDR] = @_io.kgio_addr
36 APP.call(@env.update(RACK_DEFAULTS))
38 Error.app(e) # we guarantee this does not raise