rainbows.git  about / heads / tags
Unicorn for sleepy apps and slow clients
blob d8245bd789a99a974ffdba3408d5e10bf00173f0 573 bytes (raw)
$ git show v1.0.0pre1:lib/rainbows/read_timeout.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
 
# -*- encoding: binary -*-
# :enddoc:
module Rainbows::ReadTimeout
  G = Rainbows::G # :nodoc:

  def wait_readable
    IO.select([self], nil, nil, G.kato)
  end

  # used for reading headers (respecting keepalive_timeout)
  def read_timeout(buf = "")
    expire = nil
    begin
      case rv = kgio_tryread(16384, buf)
      when :wait_readable
        now = Time.now.to_f
        if expire
          now > expire and return
        else
          expire = now + G.kato
        end
        wait_readable
      else
        return rv
      end
    end while true
  end
end

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