From 00b854e37391322c05cc16115b245d855b4970be Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Fri, 19 Nov 2010 10:19:43 +0000 Subject: [PATCH] upgrade to Kgio 2.x and Unicorn 3.x Kgio 2.0.0 has a superior API and less likely to conflict or blow up with other applications. Unicorn 3.x requires Kgio 2.x, too. --- lib/rainbows/dev_fd_response.rb | 2 +- lib/rainbows/fiber/body.rb | 2 +- lib/rainbows/fiber/io.rb | 22 ++++++++++++---------- lib/rainbows/fiber/io/methods.rb | 4 ++-- lib/rainbows/fiber/rev/methods.rb | 4 ++-- lib/rainbows/timed_read.rb | 4 ++-- rainbows.gemspec | 2 +- t/test_isolate.rb | 4 ++-- 8 files changed, 23 insertions(+), 21 deletions(-) diff --git a/lib/rainbows/dev_fd_response.rb b/lib/rainbows/dev_fd_response.rb index ec09d1e..67c94d7 100644 --- a/lib/rainbows/dev_fd_response.rb +++ b/lib/rainbows/dev_fd_response.rb @@ -54,7 +54,7 @@ class Rainbows::DevFdResponse < Struct.new(:app) # we need to make sure our pipe output is Fiber-compatible case env["rainbows.model"] when :FiberSpawn, :FiberPool, :RevFiberSpawn - io.respond_to?(:wait_readable) or + io.respond_to?(:kgio_wait_readable) or io = Rainbows::Fiber::IO.new(io) when :Revactor io = Rainbows::Revactor::Proxy.new(io) diff --git a/lib/rainbows/fiber/body.rb b/lib/rainbows/fiber/body.rb index c6c4484..f3299dc 100644 --- a/lib/rainbows/fiber/body.rb +++ b/lib/rainbows/fiber/body.rb @@ -18,7 +18,7 @@ module Rainbows::Fiber::Body # :nodoc: begin offset += (n = sock.sendfile_nonblock(body, offset, count)) rescue Errno::EAGAIN - client.wait_writable + client.kgio_wait_writable retry rescue EOFError break diff --git a/lib/rainbows/fiber/io.rb b/lib/rainbows/fiber/io.rb index a9803ee..e96f4de 100644 --- a/lib/rainbows/fiber/io.rb +++ b/lib/rainbows/fiber/io.rb @@ -53,7 +53,7 @@ class Rainbows::Fiber::IO when String buf = rv when :wait_writable - wait_writable + kgio_wait_writable end end while true else @@ -61,7 +61,7 @@ class Rainbows::Fiber::IO (rv = @to_io.write_nonblock(buf)) == buf.bytesize and return buf = byte_slice(buf, rv..-1) rescue Errno::EAGAIN - wait_writable + kgio_wait_writable end while true end end @@ -83,7 +83,7 @@ class Rainbows::Fiber::IO when :wait_readable return if expire && expire < Time.now expire ||= Time.now + G.kato - wait_readable + kgio_wait_readable else return rv end @@ -94,7 +94,7 @@ class Rainbows::Fiber::IO rescue Errno::EAGAIN return if expire && expire < Time.now expire ||= Time.now + G.kato - wait_readable + kgio_wait_readable end while true end end @@ -107,7 +107,7 @@ class Rainbows::Fiber::IO when nil raise EOFError, "end of file reached", [] when :wait_readable - wait_readable + kgio_wait_readable else return rv end @@ -116,7 +116,7 @@ class Rainbows::Fiber::IO begin return @to_io.read_nonblock(length, buf) rescue Errno::EAGAIN - wait_readable + kgio_wait_readable end while true end end @@ -141,7 +141,9 @@ end require 'rainbows/fiber/io/methods' require 'rainbows/fiber/io/compat' Rainbows::Client.__send__(:include, Rainbows::Fiber::IO::Methods) -Rainbows::Fiber::IO.__send__(:include, Rainbows::Fiber::IO::Compat) -Rainbows::Fiber::IO.__send__(:include, Rainbows::Fiber::IO::Methods) -Kgio.wait_readable = :wait_readable -Kgio.wait_writable = :wait_writable +class Rainbows::Fiber::IO + include Rainbows::Fiber::IO::Compat + include Rainbows::Fiber::IO::Methods + alias_method :wait_readable, :kgio_wait_readable + alias_method :wait_writable, :kgio_wait_writable +end diff --git a/lib/rainbows/fiber/io/methods.rb b/lib/rainbows/fiber/io/methods.rb index 941a68c..6c4d44d 100644 --- a/lib/rainbows/fiber/io/methods.rb +++ b/lib/rainbows/fiber/io/methods.rb @@ -25,7 +25,7 @@ module Rainbows::Fiber::IO::Methods super end - def wait_readable + def kgio_wait_readable fd = fileno @f = Fiber.current RD[fd] = self @@ -33,7 +33,7 @@ module Rainbows::Fiber::IO::Methods RD[fd] = nil end - def wait_writable + def kgio_wait_writable fd = fileno @f = Fiber.current WR[fd] = self diff --git a/lib/rainbows/fiber/rev/methods.rb b/lib/rainbows/fiber/rev/methods.rb index c09268f..4345bdb 100644 --- a/lib/rainbows/fiber/rev/methods.rb +++ b/lib/rainbows/fiber/rev/methods.rb @@ -21,14 +21,14 @@ module Rainbows::Fiber::Rev::Methods super end - def wait_writable + def kgio_wait_writable @w = Watcher.new(self, :w) unless defined?(@w) @w.enable unless @w.enabled? Fiber.yield @w.disable end - def wait_readable + def kgio_wait_readable @r = Watcher.new(self, :r) unless defined?(@r) @r.enable unless @r.enabled? KATO << Fiber.current diff --git a/lib/rainbows/timed_read.rb b/lib/rainbows/timed_read.rb index 4a4e027..0637cef 100644 --- a/lib/rainbows/timed_read.rb +++ b/lib/rainbows/timed_read.rb @@ -3,7 +3,7 @@ module Rainbows::TimedRead G = Rainbows::G # :nodoc: - def wait_readable + def kgio_wait_readable IO.select([self], nil, nil, G.kato) end @@ -15,7 +15,7 @@ module Rainbows::TimedRead when :wait_readable return if expire && expire < Time.now expire ||= Time.now + G.kato - wait_readable + kgio_wait_readable else return rv end diff --git a/rainbows.gemspec b/rainbows.gemspec index ef176d2..17b34aa 100644 --- a/rainbows.gemspec +++ b/rainbows.gemspec @@ -44,7 +44,7 @@ Gem::Specification.new do |s| s.add_dependency(%q, ['~> 1.1']) # we need Unicorn for the HTTP parser and process management - s.add_dependency(%q, ["~> 2.0.0"]) + s.add_dependency(%q, ["~> 3.0.0"]) s.add_development_dependency(%q, "~> 3.0.0") # optional runtime dependencies depending on configuration diff --git a/t/test_isolate.rb b/t/test_isolate.rb index 59763e0..852682a 100644 --- a/t/test_isolate.rb +++ b/t/test_isolate.rb @@ -15,8 +15,8 @@ $stdout.reopen($stderr) Isolate.now!(opts) do gem 'rack', '1.1.0' # Cramp currently requires ~> 1.1.0 - gem 'kgio', '1.3.1' - gem 'unicorn', '3.0.0pre1.9.g86d2' + gem 'kgio', '2.0.0' + gem 'unicorn', '3.0.0pre2' gem 'kcar', '0.1.1' if engine == "ruby" -- 2.11.4.GIT