rainbows.git  about / heads / tags
Unicorn for sleepy apps and slow clients
blob 9998cde097394207a8ae332f8a5826307a17619b 493 bytes (raw)
$ git show v2.0.0:lib/rainbows/fiber/rev/server.rb	# shows this blob on the CLI

 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
 
# -*- encoding: binary -*-
# :enddoc:
class Rainbows::Fiber::Rev::Server < Rev::IOWatcher
  G = Rainbows::G
  include Rainbows::ProcessClient

  def to_io
    @io
  end

  def initialize(io)
    @io = io
    super(self, :r)
  end

  def close
    detach if attached?
    @io.close
  end

  def on_readable
    return if G.cur >= MAX
    c = @io.kgio_tryaccept and Fiber.new { process(c) }.resume
  end

  def process(io)
    G.cur += 1
    process_client(io)
  ensure
    G.cur -= 1
  end
end

git clone https://yhbt.net/rainbows.git