diff options
author | Eric Wong <normalperson@yhbt.net> | 2010-10-21 16:25:39 -0700 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2010-10-22 18:37:45 +0000 |
commit | 15631717fce044fbad2f386a7b1c7daf4bdd83d2 (patch) | |
tree | f32c80aafb8b5fe13fefe9a1e3765dd757ccde7d /lib/rainbows/fiber/rev/server.rb | |
parent | d4a2b5dd2b85f4b2d3bb120ee1e1b0dde31bc25c (diff) | |
download | rainbows-15631717fce044fbad2f386a7b1c7daf4bdd83d2.tar.gz |
Despite the large number of changes, most of it is code movement here.
Diffstat (limited to 'lib/rainbows/fiber/rev/server.rb')
-rw-r--r-- | lib/rainbows/fiber/rev/server.rb | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/lib/rainbows/fiber/rev/server.rb b/lib/rainbows/fiber/rev/server.rb new file mode 100644 index 0000000..9998cde --- /dev/null +++ b/lib/rainbows/fiber/rev/server.rb @@ -0,0 +1,32 @@ +# -*- encoding: binary -*- +# :enddoc: +class Rainbows::Fiber::Rev::Server < Rev::IOWatcher + G = Rainbows::G + include Rainbows::ProcessClient + + def to_io + @io + end + + def initialize(io) + @io = io + super(self, :r) + end + + def close + detach if attached? + @io.close + end + + def on_readable + return if G.cur >= MAX + c = @io.kgio_tryaccept and Fiber.new { process(c) }.resume + end + + def process(io) + G.cur += 1 + process_client(io) + ensure + G.cur -= 1 + end +end |