repo.or.cz
/
rainbows.git
/
blob
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
log
|
graphiclog1
|
graphiclog2
|
commit
|
commitdiff
|
tree
|
refs
|
edit
|
fork
history
|
raw
|
HEAD
code shuffling for kgio
[rainbows.git]
/
lib
/
rainbows
/
fiber
/
rev
/
server.rb
blob
9998cde097394207a8ae332f8a5826307a17619b
1
# -*- encoding: binary -*-
2
# :enddoc:
3
class Rainbows::Fiber::Rev::Server < Rev::IOWatcher
4
G = Rainbows::G
5
include Rainbows::ProcessClient
6
7
def to_io
8
@io
9
end
10
11
def initialize(io)
12
@io = io
13
super(self, :r)
14
end
15
16
def close
17
detach if attached?
18
@io.close
19
end
20
21
def on_readable
22
return if G.cur >= MAX
23
c = @io.kgio_tryaccept and Fiber.new { process(c) }.resume
24
end
25
26
def process(io)
27
G.cur += 1
28
process_client(io)
29
ensure
30
G.cur -= 1
31
end
32
end