From 65f251070ce9b61a9049cb413fccffdfa11e7a70 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Tue, 28 Jun 2011 08:17:01 +0000 Subject: Fix Fiber* and WriterThread* breakage from removing io/wait This fixes up breakage introduced in commit 905f0ff393629ddb4d70e3dc221b016128c47415 to switch to kgio for timed, synchronous waiting. --- lib/rainbows/client.rb | 20 -------------------- lib/rainbows/process_client.rb | 21 ++++++++++++++++++++- lib/rainbows/socket_proxy.rb | 8 ++++++++ 3 files changed, 28 insertions(+), 21 deletions(-) diff --git a/lib/rainbows/client.rb b/lib/rainbows/client.rb index d8a30b2..b456eca 100644 --- a/lib/rainbows/client.rb +++ b/lib/rainbows/client.rb @@ -4,26 +4,6 @@ # 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 - - # 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(KEEPALIVE_TIMEOUT) - else - return rv - end - end while true - end alias write kgio_write end diff --git a/lib/rainbows/process_client.rb b/lib/rainbows/process_client.rb index 53b4f53..b685001 100644 --- a/lib/rainbows/process_client.rb +++ b/lib/rainbows/process_client.rb @@ -7,7 +7,26 @@ module Rainbows::ProcessClient NULL_IO = Unicorn::HttpRequest::NULL_IO RACK_INPUT = Unicorn::HttpRequest::RACK_INPUT IC = Unicorn::HttpRequest.input_class - Rainbows.config!(self, :client_header_buffer_size) + Rainbows.config!(self, :client_header_buffer_size, :keepalive_timeout) + + def read_expire + Time.now + 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(KEEPALIVE_TIMEOUT) + else + return rv + end + end while true + end def process_loop @hp = hp = Rainbows::HttpParser.new diff --git a/lib/rainbows/socket_proxy.rb b/lib/rainbows/socket_proxy.rb index e4cb686..c4269df 100644 --- a/lib/rainbows/socket_proxy.rb +++ b/lib/rainbows/socket_proxy.rb @@ -18,6 +18,14 @@ module Rainbows::SocketProxy to_io.kgio_trywrite(buf) end + def kgio_tryread(size, buf = "") + to_io.kgio_tryread(size, buf) + end + + def kgio_wait_readable(timeout = nil) + to_io.kgio_wait_readable(timeout) + end + def timed_read(buf) to_io.timed_read(buf) end -- cgit v1.2.3-24-ge0c7