From ad821f70a2488a91f2be1ac53cb2e64f50743989 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Tue, 28 Sep 2010 17:40:01 -0700 Subject: start using kgio library It removes the burden of byte slicing and setting file descriptor flags. In some cases, we can remove unnecessary peeraddr calls, too. --- lib/rainbows/fiber/io.rb | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'lib/rainbows/fiber/io.rb') diff --git a/lib/rainbows/fiber/io.rb b/lib/rainbows/fiber/io.rb index 4175eb0..f83b8b7 100644 --- a/lib/rainbows/fiber/io.rb +++ b/lib/rainbows/fiber/io.rb @@ -6,9 +6,9 @@ module Rainbows # #to_io method and gives users the illusion of a synchronous # interface that yields away from the current Fiber whenever # the underlying IO object cannot read or write + # + # TODO: subclass off IO and include Kgio::SocketMethods instead class IO < Struct.new(:to_io, :f) - include Rainbows::ByteSlice - # :stopdoc: LOCALHOST = Unicorn::HttpRequest::LOCALHOST @@ -17,9 +17,8 @@ module Rainbows to_io.write_nonblock(buf) end - # enough for Rainbows.addr - def peeraddr - to_io.respond_to?(:peeraddr) ? to_io.peeraddr : [ LOCALHOST ] + def kgio_addr + to_io.kgio_addr end # for wrapping output response bodies @@ -58,11 +57,14 @@ module Rainbows def write(buf) begin - (w = to_io.write_nonblock(buf)) == buf.bytesize and return - buf = byte_slice(buf, w..-1) - rescue Errno::EAGAIN - wait_writable - retry + case rv = to_io.kgio_trywrite(buf) + when nil + return + when String + buf = rv + when Kgio::WaitWritable + wait_writable + end end while true end -- cgit v1.2.3-24-ge0c7