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