quiet mismatched indentation warnings
[rainbows.git] / lib / rainbows / coolio / thread_client.rb
blobe977381ab971d8148b3da0a7d234f05c7be6ac14
1 # -*- encoding: binary -*-
2 # :enddoc:
4 RUBY_VERSION =~ %r{\A1\.8} and
5   warn "Coolio and Threads do not mix well under Ruby 1.8"
7 class Rainbows::Coolio::ThreadClient < Rainbows::Coolio::Client
8   def app_call input
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     return hijacked if @hp.hijacked?
18     ev_write_response(*response, @hp.next?)
19   rescue => e
20     handle_error(e)
21   end
23   # fails-safe application dispatch, we absolutely cannot
24   # afford to fail or raise an exception (killing the thread)
25   # here because that could cause a deadlock and we'd leak FDs
26   def app_response
27     begin
28       @env['REMOTE_ADDR'] = @_io.kgio_addr
29       @hp.hijack_setup(@_io)
30       APP.call(@env.merge!(RACK_DEFAULTS))
31     rescue => e
32       Rainbows::Error.app(e) # we guarantee this does not raise
33       [ 500, {}, [] ]
34     end
35   end
36 end