Sha256: cd65dc8cf4c80736996e2426441c1874b440fdabe2ffd2e8747ae771b6b9bf2d

Contents?: true

Size: 990 Bytes

Versions: 1

Compression:

Stored size: 990 Bytes

Contents

# -*- 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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rainbows-2.1.0 lib/rainbows/coolio/thread_client.rb