Rainbows! Rack HTTP server user/dev discussion
 help / color / Atom feed
8ea75bf03068acb95bf83fac46051d679af1af00 blob 1689 bytes (raw)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
 
# -*- encoding: binary -*-
require 'thread'

# Spawns a new thread for every client connection we accept().  This
# model is recommended for platforms like Ruby (MRI) 1.8 where spawning
# new threads is inexpensive, but still seems to work well enough with
# good native threading implementations such as NPTL under Linux on
# Ruby (MRI/YARV) 1.9
#
# This model should provide a high level of compatibility with all Ruby
# implementations, and most libraries and applications.  Applications
# running under this model should be thread-safe but not necessarily
# reentrant.
#
# If you're using green threads (MRI 1.8) and need to perform DNS lookups,
# consider using the "resolv-replace" library which replaces parts of the
# core Socket package with concurrent DNS lookup capabilities.

module Rainbows::ThreadSpawn
  include Rainbows::Base
  include Rainbows::WorkerYield

  def accept_loop(klass) #:nodoc:
    lock = Mutex.new
    limit = worker_connections
    nr = 0
    LISTENERS.each do |l|
      klass.new do
        begin
          if lock.synchronize { nr >= limit }
            worker_yield
          elsif client = l.kgio_accept(Rainbows::Client)
            klass.new(client) do |c|
              begin
                lock.synchronize { nr += 1 }
                c.process_loop
              ensure
                lock.synchronize { nr -= 1 }
              end
            end
          end
        rescue => e
          Rainbows::Error.listen_loop(e)
        end while Rainbows.alive
      end
    end
    sleep 1 while Rainbows.tick || lock.synchronize { nr > 0 }
  end

  def worker_loop(worker) #:nodoc:
    init_worker_process(worker)
    accept_loop(Thread)
  end
end
debug log:

solving 8ea75bf ...
found 8ea75bf in http://bogomips.org/rainbows-public/20170402002615.GA32751@starla/
found b304688 in http://bogomips.org/rainbows.git
preparing index
index prepared:
100644 b30468865a9b1fdb64747261c7d229be0ac7bea0	lib/rainbows/thread_spawn.rb

applying [1/1] http://bogomips.org/rainbows-public/20170402002615.GA32751@starla/
diff --git a/lib/rainbows/thread_spawn.rb b/lib/rainbows/thread_spawn.rb
index b304688..8ea75bf 100644

Checking patch lib/rainbows/thread_spawn.rb...
Applied patch lib/rainbows/thread_spawn.rb cleanly.

index at:
100644 8ea75bf03068acb95bf83fac46051d679af1af00	lib/rainbows/thread_spawn.rb

Rainbows! Rack HTTP server user/dev discussion

Archives are clonable:
	git clone --mirror http://bogomips.org/rainbows-public
	git clone --mirror http://ou63pmih66umazou.onion/rainbows-public

Example config snippet for mirrors

Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.lang.ruby.rainbows
	nntp://ou63pmih66umazou.onion/inbox.comp.lang.ruby.rainbows

 note: .onion URLs require Tor: https://www.torproject.org/

AGPL code for this site: git clone https://public-inbox.org/public-inbox.git