diff options
author | Eric Wong <normalperson@yhbt.net> | 2010-09-28 17:40:01 -0700 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2010-09-28 17:40:01 -0700 |
commit | ad821f70a2488a91f2be1ac53cb2e64f50743989 (patch) | |
tree | 6db4d334106360305ba3b66b643e8694f232fa10 /lib/rainbows/rev | |
parent | 11c75ec06ce72cea0c760161dc01a196500aa293 (diff) | |
download | rainbows-ad821f70a2488a91f2be1ac53cb2e64f50743989.tar.gz |
It removes the burden of byte slicing and setting file descriptor flags. In some cases, we can remove unnecessary peeraddr calls, too.
Diffstat (limited to 'lib/rainbows/rev')
-rw-r--r-- | lib/rainbows/rev/client.rb | 18 | ||||
-rw-r--r-- | lib/rainbows/rev/core.rb | 3 | ||||
-rw-r--r-- | lib/rainbows/rev/thread.rb | 2 |
3 files changed, 11 insertions, 12 deletions
diff --git a/lib/rainbows/rev/client.rb b/lib/rainbows/rev/client.rb index 8bfeb31..0c02525 100644 --- a/lib/rainbows/rev/client.rb +++ b/lib/rainbows/rev/client.rb @@ -5,7 +5,6 @@ module Rainbows module Rev class Client < ::Rev::IO - include Rainbows::ByteSlice include Rainbows::EvCore G = Rainbows::G F = Rainbows::StreamFile @@ -28,13 +27,14 @@ module Rainbows def write(buf) if @_write_buffer.empty? begin - w = @_io.write_nonblock(buf) - return enable_write_watcher if w == Rack::Utils.bytesize(buf) - # we never care for the return value, but yes, we may return - # a "fake" short write from super(buf) if anybody cares. - buf = byte_slice(buf, w..-1) - rescue Errno::EAGAIN - break # fall through to super(buf) + case rv = @_io.kgio_trywrite(buf) + when nil + return enable_write_watcher + when Kgio::WaitWritable + break # fall through to super(buf) + when String + buf = rv # retry, skb could grow or been drained + end rescue => e return handle_error(e) end while true @@ -104,7 +104,7 @@ module Rainbows def app_call KATO.delete(self) @env[RACK_INPUT] = @input - @env[REMOTE_ADDR] = @remote_addr + @env[REMOTE_ADDR] = @_io.kgio_addr response = APP.call(@env.update(RACK_DEFAULTS)) rev_write_response(response, alive = @hp.keepalive? && G.alive) diff --git a/lib/rainbows/rev/core.rb b/lib/rainbows/rev/core.rb index aecd5e8..2273b24 100644 --- a/lib/rainbows/rev/core.rb +++ b/lib/rainbows/rev/core.rb @@ -7,12 +7,11 @@ require 'rainbows/rev/heartbeat' module Rainbows module Rev class Server < ::Rev::IO - include Rainbows::Acceptor # CL and MAX will be defined in the corresponding worker loop def on_readable return if CONN.size >= MAX - io = accept(@_io) and CL.new(io).attach(LOOP) + io = @_io.kgio_tryaccept and CL.new(io).attach(LOOP) end end # class Server diff --git a/lib/rainbows/rev/thread.rb b/lib/rainbows/rev/thread.rb index cce3e92..7b7d455 100644 --- a/lib/rainbows/rev/thread.rb +++ b/lib/rainbows/rev/thread.rb @@ -34,7 +34,7 @@ module Rainbows # here because that could cause a deadlock and we'd leak FDs def app_response begin - @env[REMOTE_ADDR] = @remote_addr + @env[REMOTE_ADDR] = @_io.kgio_addr APP.call(@env.update(RACK_DEFAULTS)) rescue => e Error.app(e) # we guarantee this does not raise |