From 40445641f11f01c6a24bf96c8b80eed5fd33a512 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Tue, 28 Dec 2010 17:59:27 -0800 Subject: complete Rev => Coolio renaming We use Cool.io internally everywhere now, but preserve Rev-based models for anybody using them. --- lib/rainbows/coolio/thread_client.rb | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 lib/rainbows/coolio/thread_client.rb (limited to 'lib/rainbows/coolio/thread_client.rb') diff --git a/lib/rainbows/coolio/thread_client.rb b/lib/rainbows/coolio/thread_client.rb new file mode 100644 index 0000000..cc284bd --- /dev/null +++ b/lib/rainbows/coolio/thread_client.rb @@ -0,0 +1,36 @@ +# -*- encoding: binary -*- +# :enddoc: + +RUBY_VERSION =~ %r{\A1\.8} and + warn "Coolio and Threads do not mix well under Ruby 1.8" + +class Rainbows::Coolio::ThreadClient < Rainbows::Coolio::Client + def app_call + KATO.delete(self) + disable if enabled? + @env[RACK_INPUT] = @input + app_dispatch # must be implemented by subclass + end + + # this is only called in the master thread + def response_write(response) + alive = @hp.next? && G.alive + coolio_write_response(response, alive) + return quit unless alive && :close != @state + + @state = :headers + end + + # fails-safe application dispatch, we absolutely cannot + # afford to fail or raise an exception (killing the thread) + # here because that could cause a deadlock and we'd leak FDs + def app_response + begin + @env[REMOTE_ADDR] = @_io.kgio_addr + APP.call(@env.update(RACK_DEFAULTS)) + rescue => e + Rainbows::Error.app(e) # we guarantee this does not raise + [ 500, {}, [] ] + end + end +end -- cgit v1.2.3-24-ge0c7