rainbows/rev/* require/autoload cleanup
[rainbows.git] / lib / rainbows / rev / thread_client.rb
blobd6e6655c63f0cb88e995f8165a74d1654cf79d35
1 # -*- encoding: binary -*-
2 # :enddoc:
4 RUBY_VERSION =~ %r{\A1\.8} and
5   warn "Rev and Threads do not mix well under Ruby 1.8"
7 class Rainbows::Rev::ThreadClient < Rainbows::Rev::Client
8   def app_call
9     KATO.delete(self)
10     disable if enabled?
11     @env[RACK_INPUT] = @input
12     app_dispatch # must be implemented by subclass
13   end
15   # this is only called in the master thread
16   def response_write(response)
17     alive = @hp.next? && G.alive
18     rev_write_response(response, alive)
19     return quit unless alive && :close != @state
21     @state = :headers
22   end
24   # fails-safe application dispatch, we absolutely cannot
25   # afford to fail or raise an exception (killing the thread)
26   # here because that could cause a deadlock and we'd leak FDs
27   def app_response
28     begin
29       @env[REMOTE_ADDR] = @_io.kgio_addr
30       APP.call(@env.update(RACK_DEFAULTS))
31     rescue => e
32       Rainbows::Error.app(e) # we guarantee this does not raise
33       [ 500, {}, [] ]
34     end
35   end
36 end