1 # -*- encoding: binary -*-
4 # Spawns a new thread for every client connection we accept(). This
5 # model is recommended for platforms like Ruby 1.8 where spawning new
6 # threads is inexpensive.
8 # This model should provide a high level of compatibility with all
9 # Ruby implementations, and most libraries and applications.
10 # Applications running under this model should be thread-safe
11 # but not necessarily reentrant.
13 # If you're connecting to external services and need to perform DNS
14 # lookups, consider using the "resolv-replace" library which replaces
15 # parts of the core Socket package with concurrent DNS lookup
18 module Rainbows::ThreadSpawn
19 include Rainbows::Base
20 include Rainbows::WorkerYield
22 def accept_loop(klass) #:nodoc:
24 limit = worker_connections
28 if lock.synchronize { G.cur >= limit }
30 elsif c = l.kgio_accept
33 lock.synchronize { G.cur += 1 }
36 lock.synchronize { G.cur -= 1 }
41 Rainbows::Error.listen_loop(e)
45 sleep 1 while G.tick || lock.synchronize { G.cur > 0 }
48 def worker_loop(worker) #:nodoc:
49 init_worker_process(worker)