rainbows.git  about / heads / tags
Unicorn for sleepy apps and slow clients
blob cc02c0b696637f0f0a00384f45f42cefbabbb06f 747 bytes (raw)
$ git show v4.0.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
32
33
34
 
# -*- encoding: binary -*-
# :enddoc:
require "io/wait"

# this class is used for most synchronous concurrency models
class Rainbows::Client < Kgio::Socket
  include Rainbows::ProcessClient
  Rainbows.config!(self, :keepalive_timeout)

  def read_expire
    Time.now + KEEPALIVE_TIMEOUT
  end

  def kgio_wait_readable
    wait KEEPALIVE_TIMEOUT
  end

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

  alias write kgio_write
end

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