diff options
author | Eric Wong <normalperson@yhbt.net> | 2010-10-21 16:25:39 -0700 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2010-10-22 18:37:45 +0000 |
commit | 15631717fce044fbad2f386a7b1c7daf4bdd83d2 (patch) | |
tree | f32c80aafb8b5fe13fefe9a1e3765dd757ccde7d /lib/rainbows/read_timeout.rb | |
parent | d4a2b5dd2b85f4b2d3bb120ee1e1b0dde31bc25c (diff) | |
download | rainbows-15631717fce044fbad2f386a7b1c7daf4bdd83d2.tar.gz |
Despite the large number of changes, most of it is code movement here.
Diffstat (limited to 'lib/rainbows/read_timeout.rb')
-rw-r--r-- | lib/rainbows/read_timeout.rb | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/lib/rainbows/read_timeout.rb b/lib/rainbows/read_timeout.rb new file mode 100644 index 0000000..d8245bd --- /dev/null +++ b/lib/rainbows/read_timeout.rb @@ -0,0 +1,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 |