code shuffling for kgio
[rainbows.git] / lib / rainbows / fiber / rev / server.rb
blob9998cde097394207a8ae332f8a5826307a17619b
1 # -*- encoding: binary -*-
2 # :enddoc:
3 class Rainbows::Fiber::Rev::Server < Rev::IOWatcher
4   G = Rainbows::G
5   include Rainbows::ProcessClient
7   def to_io
8     @io
9   end
11   def initialize(io)
12     @io = io
13     super(self, :r)
14   end
16   def close
17     detach if attached?
18     @io.close
19   end
21   def on_readable
22     return if G.cur >= MAX
23     c = @io.kgio_tryaccept and Fiber.new { process(c) }.resume
24   end
26   def process(io)
27     G.cur += 1
28     process_client(io)
29   ensure
30     G.cur -= 1
31   end
32 end