connection: connect before select

a refactoring was performed on the connection, so they could connect out
of the #to_io call; in order to proper read the interests, it was
thought that it was too late at that point, as interests before #to_io
would be different from post #to_io; this makes our selector less
"portable", as we rely on internal logic being called now
This commit is contained in:
HoneyryderChuck 2020-04-14 16:01:39 +01:00
parent 382139e0a5
commit 93e30f0abf
6 changed files with 34 additions and 28 deletions

View File

@ -191,14 +191,28 @@ module HTTPX
nil
end
def connect
transition(:open)
end
def to_io
case @state
when :idle
transition(:open)
end
@io.to_io
end
def call
case @state
when :closed
return
when :closing
dwrite
transition(:closed)
emit(:close)
when :open
consume
end
nil
end
def close
@parser.close if @parser
return unless @keep_alive_timer
@ -224,20 +238,6 @@ module HTTPX
end
end
def call
case @state
when :closed
return
when :closing
dwrite
transition(:closed)
emit(:close)
when :open
consume
end
nil
end
def timeout
return @timeout if defined?(@timeout)

View File

@ -20,13 +20,8 @@ module HTTPX
@state = :negotiated if @keep_open
end
# TODO: come back to this once we have the loops figured out
# def interests
# @interests || super
# end
def interests
:rw
@interests || super
end
def protocol

View File

@ -179,7 +179,7 @@ module HTTPX
super || @state == :connecting || @state == :connected
end
def to_io
def connect
return super unless @options.proxy
case @state
@ -188,11 +188,11 @@ module HTTPX
when :connected
transition(:open)
end
@io.to_io
end
def call
super
return unless @options.proxy
case @state

View File

@ -25,7 +25,7 @@ module HTTPX
def_delegator :@connections, :empty?
def_delegators :@resolver_connection, :to_io, :call, :interests, :close
def_delegators :@resolver_connection, :connect, :connecting?, :to_io, :call, :interests, :close
def initialize(options)
@options = Options.new(options)

View File

@ -72,7 +72,11 @@ module HTTPX
@state == :closed
end
def to_io
def connecting?
@state == :idle
end
def connect
case @state
when :idle
transition(:open)
@ -81,6 +85,9 @@ module HTTPX
transition(:open)
end
resolve if @queries.empty?
end
def to_io
@io.to_io
end

View File

@ -90,6 +90,8 @@ class HTTPX::Selector
w = nil
@selectables.each_key do |io|
io.connect if io.connecting?
(r ||= []) << io if io.interests == :r || io.interests == :rw
(w ||= []) << io if io.interests == :w || io.interests == :rw
end
@ -123,6 +125,8 @@ class HTTPX::Selector
def select_one(interval)
io, monitor = @selectables.first
io.connect if io.connecting?
result = case io.interests
when :r then io.to_io.wait_readable(interval)
when :w then io.to_io.wait_writable(interval)