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
29 if lock.synchronize { nr >= limit }
31 elsif c = l.kgio_accept
34 lock.synchronize { nr += 1 }
37 lock.synchronize { nr -= 1 }
42 Rainbows::Error.listen_loop(e)
43 end while Rainbows.alive
46 sleep 1 while Rainbows.tick || lock.synchronize { nr > 0 }
49 def worker_loop(worker) #:nodoc:
50 init_worker_process(worker)