doc: rdoc cleanups and fixes
[rainbows.git] / lib / rainbows / epoll / server.rb
blob58e7653a9b88c02e6d0ba3fa46253e9d844d3606
1 # -*- encoding: binary -*-
2 # :enddoc:
3 module Rainbows::Epoll::Server
4   @@nr = 0
5   Rainbows::Epoll.nr_clients = lambda { @@nr }
6   IN = SleepyPenguin::Epoll::IN | SleepyPenguin::Epoll::ET
7   MAX = Rainbows.server.worker_connections
8   THRESH = MAX - 1
9   LISTENERS = Rainbows::HttpServer::LISTENERS
10   EP = Rainbows::Epoll::EP
12   def self.run
13     LISTENERS.each { |sock| EP.add(sock.extend(self), IN) }
14     Rainbows::Epoll.loop
15   end
17   # rearms all listeners when there's a free slot
18   def self.decr
19     THRESH == (@@nr -= 1) and LISTENERS.each { |sock| EP.set(sock, IN) }
20   end
22   def epoll_run
23     return EP.delete(self) if @@nr >= MAX
24     while io = kgio_tryaccept
25       @@nr += 1
26       # there's a chance the client never even sees epoll for simple apps
27       io.epoll_once
28       return EP.delete(self) if @@nr >= MAX
29     end
30   end
31 end