From 15631717fce044fbad2f386a7b1c7daf4bdd83d2 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Thu, 21 Oct 2010 16:25:39 -0700 Subject: code shuffling for kgio Despite the large number of changes, most of it is code movement here. --- lib/rainbows/fiber/io/methods.rb | 44 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 lib/rainbows/fiber/io/methods.rb (limited to 'lib/rainbows/fiber/io/methods.rb') diff --git a/lib/rainbows/fiber/io/methods.rb b/lib/rainbows/fiber/io/methods.rb new file mode 100644 index 0000000..663fdb4 --- /dev/null +++ b/lib/rainbows/fiber/io/methods.rb @@ -0,0 +1,44 @@ +# -*- encoding: binary -*- + +module Rainbows::Fiber::IO::Methods + RD = Rainbows::Fiber::RD + WR = Rainbows::Fiber::WR + attr_accessor :f + + # for wrapping output response bodies + def each(&block) + if buf = kgio_read(16384) + yield buf + yield buf while kgio_read(16384, buf) + end + self + end + + def close + fd = fileno + RD[fd] = WR[fd] = nil + super + end + + def wait_readable + fd = fileno + @f = Fiber.current + RD[fd] = self + Fiber.yield + RD[fd] = nil + end + + def wait_writable + fd = fileno + @f = Fiber.current + WR[fd] = self + Fiber.yield + WR[fd] = nil + end + + def self.included(klass) + if klass.method_defined?(:kgio_write) + klass.__send__(:alias_method, :write, :kgio_write) + end + end +end -- cgit v1.2.3-24-ge0c7