1 # -*- encoding: binary -*-
2 module Rainbows::XEpollThreadSpawn::Client
3 HBUFSIZ = Rainbows.client_header_buffer_size
5 max = Rainbows.server.worker_connections
6 ACCEPTORS = Rainbows::HttpServer::LISTENERS.map do |sock|
11 if io = sock.kgio_accept(Rainbows::Client)
15 sleep while N[0] >= max
17 Rainbows::Error.listen_loop(e)
18 end while Rainbows.alive
22 ep = SleepyPenguin::Epoll
24 IN = ep::IN | ep::ET | ep::ONESHOT
27 KATO.compare_by_identity if KATO.respond_to?(:compare_by_identity)
29 @@last_expire = Time.now
32 LOCK.synchronize { KATO[self] = @@last_expire }
37 LOCK.synchronize { KATO.delete self }
41 ACCEPTORS.each { |thr| thr.run }
44 EP.wait(nil, 1000) { |fl, obj| obj.epoll_run(buf) }
48 Rainbows::Error.listen_loop(e)
49 end while Rainbows.tick || N[0] > 0
50 Rainbows::JoinThreads.acceptors(ACCEPTORS)
54 return if ((now = Time.now) - @@last_expire) < 1.0
55 if (ot = Rainbows.keepalive_timeout) >= 0
59 KATO.delete_if { |client, time| time < ot and client.timeout!(defer) }
61 defer.each { |io| io.closed? or io.close }
67 @hp = Rainbows::HttpParser.new
78 N.decr(0, 1) == THRESH and ACCEPTORS.each { |t| t.run }
88 case kgio_tryread(HBUFSIZ, buf)
94 env = @hp.parse and return spawn(env, @hp)
103 Thread.new { process_pipeline(env, hp) }
106 def pipeline_ready(hp)
107 env = hp.parse and return env
108 case buf = kgio_tryread(HBUFSIZ)
114 env = hp.parse and return env