1 # -*- encoding: binary -*-
3 module Rainbows::Epoll::Server
4 IN = SleepyPenguin::Epoll::IN | SleepyPenguin::Epoll::ET
6 MAX = Rainbows.server.worker_connections
8 include Rainbows::Epoll::State
9 LISTENERS = Rainbows::HttpServer::LISTENERS
12 def self.extended(obj)
13 obj.instance_variable_set(:@epoll_active, false)
17 LISTENERS.each { |sock| sock.extend(self).epoll_enable(IN) }
19 EP.wait(100, 1000) { |_, obj| obj.epoll_run }
20 while obj = ReRun.shift
23 Rainbows::Epoll::Client.expire
25 Rainbows::Error.listen_loop(e)
26 end while Rainbows.tick || @@nr > 0
29 # rearms all listeners when there's a free slot
31 THRESH == (@@nr -= 1) and LISTENERS.each { |sock| sock.epoll_enable(IN) }
35 return epoll_disable if @@nr >= MAX
36 while io = kgio_tryaccept
38 # there's a chance the client never even sees epoll for simple apps
40 return epoll_disable if @@nr >= MAX