epoll: make Epoll.quit more reusable
[rainbows.git] / lib / rainbows / epoll.rb
blob54d08fbfb14c6e5c50390decdec529737fd1f057
1 # -*- encoding: binary -*-
2 # :enddoc:
3 require 'sleepy_penguin'
4 require 'sendfile'
6 # Edge-triggered epoll concurrency model.  This is extremely unfair
7 # and optimized for throughput at the expense of fairness
8 module Rainbows::Epoll
9   include Rainbows::Base
10   autoload :Server, 'rainbows/epoll/server'
11   autoload :Client, 'rainbows/epoll/client'
12   autoload :ResponsePipe, 'rainbows/epoll/response_pipe'
13   autoload :ResponseChunkPipe, 'rainbows/epoll/response_chunk_pipe'
15   def self.quit!
16     Rainbows.quit!
17     EP.close unless EP.closed?
18   end
20   def init_worker_process(worker)
21     super
22     Rainbows::Epoll.const_set :EP, SleepyPenguin::Epoll.new
23     trap(:QUIT) { Rainbows::Epoll.quit! }
24     Rainbows::Client.__send__ :include, Client
25   end
27   def worker_loop(worker) # :nodoc:
28     init_worker_process(worker)
29     Server.run
30   end
31 end