From d4a2b5dd2b85f4b2d3bb120ee1e1b0dde31bc25c Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Wed, 20 Oct 2010 17:48:58 -0700 Subject: unicorn 2.x updates + kgio We get basic internal API changes from Unicorn, code simplifications coming next. --- lib/rainbows/fiber/io.rb | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) (limited to 'lib/rainbows/fiber/io.rb') diff --git a/lib/rainbows/fiber/io.rb b/lib/rainbows/fiber/io.rb index f83b8b7..571f070 100644 --- a/lib/rainbows/fiber/io.rb +++ b/lib/rainbows/fiber/io.rb @@ -10,7 +10,7 @@ module Rainbows # TODO: subclass off IO and include Kgio::SocketMethods instead class IO < Struct.new(:to_io, :f) # :stopdoc: - LOCALHOST = Unicorn::HttpRequest::LOCALHOST + LOCALHOST = Kgio::LOCALHOST # needed to write errors with def write_nonblock(buf) @@ -82,14 +82,36 @@ module Rainbows end def readpartial(length, buf = "") - begin - to_io.read_nonblock(length, buf) - rescue Errno::EAGAIN - wait_readable - retry + if to_io.respond_to?(:kgio_tryread) + # TODO: use kgio_read! + begin + rv = to_io.kgio_tryread(length, buf) + case rv + when nil + raise EOFError, "end of file reached", [] + when Kgio::WaitReadable + wait_readable + else + return rv + end + end while true + else + begin + to_io.read_nonblock(length, buf) + rescue Errno::EAGAIN + wait_readable + retry + end end end + def kgio_read(*args) + to_io.kgio_read(*args) + end + + def kgio_read!(*args) + to_io.kgio_read!(*args) + end end end end -- cgit v1.2.3-24-ge0c7