setting monitor interests programatically instead of the :rw everywhere (so timeouts work properly)

This commit is contained in:
HoneyryderChuck 2018-02-17 20:40:35 +00:00
parent 0dd9d1152c
commit e8c150dbca
2 changed files with 15 additions and 3 deletions

View File

@ -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

View File

@ -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