1 # -*- encoding: binary -*-
3 require 'rainbows/rev/master'
8 class ThreadClient < Client
13 @env[RACK_INPUT] = @input
14 @input = nil # not sure why, @input seems to get closed otherwise...
15 app_dispatch # must be implemented by subclass
18 # this is only called in the master thread
19 def response_write(response)
21 alive = @hp.keepalive? && G.alive
22 out = [ alive ? CONN_ALIVE : CONN_CLOSE ] if @hp.headers?
23 DeferredResponse.write(self, response, out)
24 return quit unless alive && G.alive
29 # keepalive requests are always body-less, so @input is unchanged
30 if @hp.headers(@env, @buf)
31 @input = HttpRequest::NULL_IO
38 # fails-safe application dispatch, we absolutely cannot
39 # afford to fail or raise an exception (killing the thread)
40 # here because that could cause a deadlock and we'd leak FDs
43 @env[REMOTE_ADDR] = @remote_addr
44 APP.call(@env.update(RACK_DEFAULTS))
46 Error.app(e) # we guarantee this does not raise