rainbows.git  about / heads / tags
Unicorn for sleepy apps and slow clients
blob 9b65cea0aac44bd5bad8c4222d7e1a85deb13c83 674 bytes (raw)
$ git show v3.2.0:lib/rainbows/client.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
 
# -*- encoding: binary -*-
# :enddoc:
require "io/wait"

# this class is used for most synchronous concurrency models
class Rainbows::Client < Kgio::Socket
  def read_expire
    Time.now + Rainbows.keepalive_timeout
  end

  def kgio_wait_readable
    wait Rainbows.keepalive_timeout
  end

  # used for reading headers (respecting keepalive_timeout)
  def timed_read(buf)
    expire = nil
    begin
      case rv = kgio_tryread(16384, buf)
      when :wait_readable
        return if expire && expire < Time.now
        expire ||= read_expire
        kgio_wait_readable
      else
        return rv
      end
    end while true
  end

  include Rainbows::ProcessClient
end

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