diff options
author | Eric Wong <normalperson@yhbt.net> | 2011-01-05 16:33:04 -0800 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2011-01-06 07:16:55 +0000 |
commit | ea6831e1eaeeb862afa7ed9213e2d9bc0180e706 (patch) | |
tree | 34079935b061a9f855ffe2aee49c736a4faf8867 /lib/rainbows/client.rb | |
parent | ed7669ced3aba5c0ba6f5fbee9411546b32c96df (diff) | |
download | rainbows-ea6831e1eaeeb862afa7ed9213e2d9bc0180e706.tar.gz |
No need to split it out when there's only a single class using it.
Diffstat (limited to 'lib/rainbows/client.rb')
-rw-r--r-- | lib/rainbows/client.rb | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/lib/rainbows/client.rb b/lib/rainbows/client.rb index 8425e9e..3d92da1 100644 --- a/lib/rainbows/client.rb +++ b/lib/rainbows/client.rb @@ -3,6 +3,28 @@ # this class is used for most synchronous concurrency models class Rainbows::Client < Kgio::Socket - include Rainbows::TimedRead + def read_expire + Time.now + Rainbows.keepalive_timeout + end + + def kgio_wait_readable + IO.select([self], nil, nil, 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 |