From 869e0d5da8cbe8959983ed66e2b4c31dc7a37d92 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sun, 26 Dec 2010 21:40:34 +0000 Subject: rename rev/thread => rev/thread_client While we're at it, unindent --- lib/rainbows/rev/thread.rb | 45 --------------------------------------- lib/rainbows/rev/thread_client.rb | 38 +++++++++++++++++++++++++++++++++ lib/rainbows/rev_thread_pool.rb | 2 +- lib/rainbows/rev_thread_spawn.rb | 2 +- 4 files changed, 40 insertions(+), 47 deletions(-) delete mode 100644 lib/rainbows/rev/thread.rb create mode 100644 lib/rainbows/rev/thread_client.rb diff --git a/lib/rainbows/rev/thread.rb b/lib/rainbows/rev/thread.rb deleted file mode 100644 index 276b315..0000000 --- a/lib/rainbows/rev/thread.rb +++ /dev/null @@ -1,45 +0,0 @@ -# -*- encoding: binary -*- -# :enddoc: -require 'thread' -require 'rainbows/rev/master' - -RUBY_VERSION =~ %r{\A1\.8} and - warn "Rev and Threads do not mix well under Ruby 1.8" - -module Rainbows - module Rev - - class ThreadClient < 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 - rev_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 - Error.app(e) # we guarantee this does not raise - [ 500, {}, [] ] - end - end - - end - end -end diff --git a/lib/rainbows/rev/thread_client.rb b/lib/rainbows/rev/thread_client.rb new file mode 100644 index 0000000..e529b5b --- /dev/null +++ b/lib/rainbows/rev/thread_client.rb @@ -0,0 +1,38 @@ +# -*- encoding: binary -*- +# :enddoc: +require 'thread' +require 'rainbows/rev/master' + +RUBY_VERSION =~ %r{\A1\.8} and + warn "Rev and Threads do not mix well under Ruby 1.8" + +class Rainbows::Rev::ThreadClient < Rainbows::Rev::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 + rev_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 diff --git a/lib/rainbows/rev_thread_pool.rb b/lib/rainbows/rev_thread_pool.rb index 5e5f14a..b31e1f5 100644 --- a/lib/rainbows/rev_thread_pool.rb +++ b/lib/rainbows/rev_thread_pool.rb @@ -1,5 +1,5 @@ # -*- encoding: binary -*- -require 'rainbows/rev/thread' +require 'rainbows/rev/thread_client' module Rainbows diff --git a/lib/rainbows/rev_thread_spawn.rb b/lib/rainbows/rev_thread_spawn.rb index 68e774b..38771d3 100644 --- a/lib/rainbows/rev_thread_spawn.rb +++ b/lib/rainbows/rev_thread_spawn.rb @@ -1,5 +1,5 @@ # -*- encoding: binary -*- -require 'rainbows/rev/thread' +require 'rainbows/rev/thread_client' module Rainbows -- cgit v1.2.3-24-ge0c7