mirror of
https://github.com/HoneyryderChuck/httpx.git
synced 2025-08-10 00:01:27 -04:00
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:
parent
382139e0a5
commit
93e30f0abf
@ -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)
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user