1 # -*- encoding: binary -*-
3 module Rainbows::Epoll::Server
4 IN = SleepyPenguin::Epoll::IN | SleepyPenguin::Epoll::ET
6 MAX = Rainbows.server.worker_connections
8 LISTENERS = Rainbows::HttpServer::LISTENERS
10 EP = Rainbows::Epoll::EP
13 LISTENERS.each { |sock| EP.add(sock.extend(self), IN) }
15 EP.wait(nil, 1000) { |_, obj| obj.epoll_run }
16 while obj = ReRun.shift
19 Rainbows::Epoll::Client.expire
22 Rainbows::Error.listen_loop(e)
23 end while Rainbows.tick || @@nr > 0
26 # rearms all listeners when there's a free slot
28 THRESH == (@@nr -= 1) and LISTENERS.each { |sock| EP.set(sock, IN) }
32 return EP.delete(self) if @@nr >= MAX
33 while io = kgio_tryaccept
35 # there's a chance the client never even sees epoll for simple apps
37 return EP.delete(self) if @@nr >= MAX