1 # -*- encoding: binary -*-
3 require "sleepy_penguin"
6 module Rainbows::XEpollThreadSpawn::Client
7 HBUFSIZ = Rainbows.client_header_buffer_size
9 max = Rainbows.server.worker_connections
10 ACCEPTORS = Rainbows::HttpServer::LISTENERS.map do |sock|
15 if io = sock.kgio_accept(Rainbows::Client)
19 sleep while N[0] >= max
21 Rainbows::Error.listen_loop(e)
22 end while Rainbows.alive
26 ep = SleepyPenguin::Epoll
28 IN = ep::IN | ep::ET | ep::ONESHOT
31 KATO.compare_by_identity if KATO.respond_to?(:compare_by_identity)
33 @@last_expire = Time.now
36 LOCK.synchronize { KATO[self] = @@last_expire }
41 LOCK.synchronize { KATO.delete self }
45 ACCEPTORS.each { |thr| thr.run }
48 EP.wait(nil, 1000) { |fl, obj| obj.epoll_run(buf) }
52 Rainbows::Error.listen_loop(e)
53 end while Rainbows.tick || N[0] > 0
54 Rainbows::JoinThreads.acceptors(ACCEPTORS)
58 return if ((now = Time.now) - @@last_expire) < 1.0
59 if (ot = Rainbows.keepalive_timeout) >= 0
63 KATO.delete_if { |client, time| time < ot and client.timeout!(defer) }
65 defer.each { |io| io.closed? or io.close }
71 @hp = Rainbows::HttpParser.new
82 N.decr(0, 1) == THRESH and ACCEPTORS.each { |t| t.run }
92 case kgio_tryread(HBUFSIZ, buf)
98 env = @hp.parse and return spawn(env, @hp)
107 Thread.new { process_pipeline(env, hp) }
110 def pipeline_ready(hp)
111 env = hp.parse and return env
112 case buf = kgio_tryread(HBUFSIZ)
118 env = hp.parse and return env