From e8c150dbca6e199a30bd2f830e37fbb0bb8dc28c Mon Sep 17 00:00:00 2001 From: HoneyryderChuck Date: Sat, 17 Feb 2018 20:40:35 +0000 Subject: [PATCH] setting monitor interests programatically instead of the :rw everywhere (so timeouts work properly) --- lib/httpx/channel.rb | 15 +++++++++++++-- lib/httpx/connection.rb | 3 ++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/lib/httpx/channel.rb b/lib/httpx/channel.rb index 49d60d73..3af93ca7 100644 --- a/lib/httpx/channel.rb +++ b/lib/httpx/channel.rb @@ -61,7 +61,7 @@ module HTTPX @io = io @options = Options.new(options) @window_size = @options.window_size - @read_buffer = "".b + @read_buffer = Buffer.new(BUFFER_SIZE) @write_buffer = Buffer.new(BUFFER_SIZE) @pending = [] @state = :idle @@ -79,6 +79,17 @@ module HTTPX uri.scheme == @io.scheme end + def interests + return :w if @state == :idle + readable = !@read_buffer.full? + writable = !@write_buffer.empty? + if readable + writable ? :rw : :r + else + writable ? :w : :r + end + end + def to_io case @state when :idle @@ -134,7 +145,7 @@ module HTTPX throw(:close, self) unless siz return if siz.zero? log { "READ: #{siz} bytes..." } - parser << @read_buffer + parser << @read_buffer.to_s end end diff --git a/lib/httpx/connection.rb b/lib/httpx/connection.rb index 675fefcb..236dbeac 100644 --- a/lib/httpx/connection.rb +++ b/lib/httpx/connection.rb @@ -21,6 +21,7 @@ module HTTPX if (channel = monitor.value) consume(channel) end + monitor.interests = channel.interests end end @@ -57,7 +58,7 @@ module HTTPX private def register_channel(channel) - monitor = @selector.register(channel, :rw) + monitor = @selector.register(channel, :w) monitor.value = channel @channels << channel end