globally refactor Range handling for responses
[rainbows.git] / lib / rainbows / fiber / coolio / server.rb
blobb0649532200c502f409ecf2c64ade6010c1d5bfd
1 # -*- encoding: binary -*-
2 # :enddoc:
3 class Rainbows::Fiber::Coolio::Server < Coolio::IOWatcher
4   G = Rainbows::G
6   def to_io
7     @io
8   end
10   def initialize(io)
11     @io = io
12     super(self, :r)
13   end
15   def close
16     detach if attached?
17     @io.close
18   end
20   def on_readable
21     return if G.cur >= MAX
22     c = @io.kgio_tryaccept and Fiber.new { process(c) }.resume
23   end
25   def process(io)
26     G.cur += 1
27     io.process_loop
28   ensure
29     G.cur -= 1
30   end
31 end