diff options
author | Eric Wong <normalperson@yhbt.net> | 2010-12-30 08:33:15 +0000 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2011-01-04 16:37:42 -0800 |
commit | e21939d776673b2f8887adf7a5c64812b7d2e98e (patch) | |
tree | 48aa3a71201e770758bd09b325c3f2704411af7f /lib/rainbows/revactor/client.rb | |
parent | 4a76da1833922c74e147be5def9bfe04fd0c16a2 (diff) | |
download | rainbows-e21939d776673b2f8887adf7a5c64812b7d2e98e.tar.gz |
Rack::Utils::HeaderHash is still very expensive in Rack 1.2, especially for simple things that we want to run as fast as possible with minimal interference. HeaderHash is unnecessary for most requests that do not send Content-Range in responses.
Diffstat (limited to 'lib/rainbows/revactor/client.rb')
-rw-r--r-- | lib/rainbows/revactor/client.rb | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/lib/rainbows/revactor/client.rb b/lib/rainbows/revactor/client.rb new file mode 100644 index 0000000..7c4b53d --- /dev/null +++ b/lib/rainbows/revactor/client.rb @@ -0,0 +1,59 @@ +# -*- encoding: binary -*- +# :enddoc: +require 'fcntl' +class Rainbows::Revactor::Client + autoload :TeeSocket, 'rainbows/revactor/client/tee_socket' + RD_ARGS = {} + RD_ARGS[:timeout] = Rainbows::G.kato if Rainbows::G.kato > 0 + attr_reader :kgio_addr + + def initialize(client) + @client, @rd_args, @ts = client, [ nil ], nil + io = client.instance_variable_get(:@_io) + io.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC) + @kgio_addr = if Revactor::TCP::Socket === client + @rd_args << RD_ARGS + client.remote_addr + else + Kgio::LOCALHOST + end + end + + def kgio_read!(nr, buf) + buf.replace(@client.read) + end + + def write(buf) + @client.write(buf) + end + + def write_nonblock(buf) # only used for errors + @client.instance_variable_get(:@_io).write_nonblock(buf) + end + + def timed_read(buf2) + buf2.replace(@client.read(*@rd_args)) + end + + def set_input(env, hp) + env[RACK_INPUT] = 0 == hp.content_length ? + NULL_IO : IC.new(@ts = TeeSocket.new(@client), hp) + env[CLIENT_IO] = @client + end + + def close + @client.close + @client = nil + end + + def closed? + @client.nil? + end + + def self.setup + self.const_set(:IC, Unicorn::HttpRequest.input_class) + include Rainbows::ProcessClient + include Methods + end +end +require 'rainbows/revactor/client/methods' |