mirror of
https://github.com/HoneyryderChuck/httpx.git
synced 2025-10-07 00:05:02 -04:00
remove connect call from selector, making it implicit when selecting interests
This commit is contained in:
parent
f977db76ef
commit
ec6e39d7b9
@ -181,9 +181,9 @@ module HTTPX
|
|||||||
def interests
|
def interests
|
||||||
# connecting
|
# connecting
|
||||||
if connecting?
|
if connecting?
|
||||||
return :w unless @io
|
connect
|
||||||
|
|
||||||
return @io.interests
|
return @io.interests if connecting?
|
||||||
end
|
end
|
||||||
|
|
||||||
# if the write buffer is full, we drain it
|
# if the write buffer is full, we drain it
|
||||||
@ -194,10 +194,6 @@ module HTTPX
|
|||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
|
|
||||||
def connect
|
|
||||||
transition(:open)
|
|
||||||
end
|
|
||||||
|
|
||||||
def to_io
|
def to_io
|
||||||
@io.to_io
|
@io.to_io
|
||||||
end
|
end
|
||||||
@ -251,6 +247,10 @@ module HTTPX
|
|||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def connect
|
||||||
|
transition(:open)
|
||||||
|
end
|
||||||
|
|
||||||
def exhausted?
|
def exhausted?
|
||||||
@parser && parser.exhausted?
|
@parser && parser.exhausted?
|
||||||
end
|
end
|
||||||
|
@ -93,6 +93,7 @@ module HTTPX
|
|||||||
buffer.bytesize
|
buffer.bytesize
|
||||||
rescue ::IO::WaitReadable,
|
rescue ::IO::WaitReadable,
|
||||||
::IO::WaitWritable
|
::IO::WaitWritable
|
||||||
|
buffer.clear
|
||||||
0
|
0
|
||||||
rescue EOFError
|
rescue EOFError
|
||||||
nil
|
nil
|
||||||
|
@ -179,17 +179,6 @@ module HTTPX
|
|||||||
super || @state == :connecting || @state == :connected
|
super || @state == :connecting || @state == :connected
|
||||||
end
|
end
|
||||||
|
|
||||||
def connect
|
|
||||||
return super unless @options.proxy
|
|
||||||
|
|
||||||
case @state
|
|
||||||
when :idle
|
|
||||||
transition(:connecting)
|
|
||||||
when :connected
|
|
||||||
transition(:open)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def call
|
def call
|
||||||
super
|
super
|
||||||
|
|
||||||
@ -210,6 +199,19 @@ module HTTPX
|
|||||||
emit(:close)
|
emit(:close)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def connect
|
||||||
|
return super unless @options.proxy
|
||||||
|
|
||||||
|
case @state
|
||||||
|
when :idle
|
||||||
|
transition(:connecting)
|
||||||
|
when :connected
|
||||||
|
transition(:open)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def transition(nextstate)
|
def transition(nextstate)
|
||||||
return super unless @options.proxy
|
return super unless @options.proxy
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ module HTTPX
|
|||||||
|
|
||||||
def_delegator :@connections, :empty?
|
def_delegator :@connections, :empty?
|
||||||
|
|
||||||
def_delegators :@resolver_connection, :connect, :connecting?, :to_io, :call, :interests, :close
|
def_delegators :@resolver_connection, :connecting?, :to_io, :call, :close
|
||||||
|
|
||||||
def initialize(options)
|
def initialize(options)
|
||||||
@options = Options.new(options)
|
@options = Options.new(options)
|
||||||
@ -62,8 +62,20 @@ module HTTPX
|
|||||||
resolver_connection.closed?
|
resolver_connection.closed?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def interests
|
||||||
|
return if @queries.empty?
|
||||||
|
|
||||||
|
resolver_connection.__send__(__method__)
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def connect
|
||||||
|
return if @queries.empty?
|
||||||
|
|
||||||
|
resolver_connection.__send__(__method__)
|
||||||
|
end
|
||||||
|
|
||||||
def pool
|
def pool
|
||||||
Thread.current[:httpx_connection_pool] ||= Pool.new
|
Thread.current[:httpx_connection_pool] ||= Pool.new
|
||||||
end
|
end
|
||||||
|
@ -72,21 +72,6 @@ module HTTPX
|
|||||||
@state == :closed
|
@state == :closed
|
||||||
end
|
end
|
||||||
|
|
||||||
def connecting?
|
|
||||||
@state == :idle
|
|
||||||
end
|
|
||||||
|
|
||||||
def connect
|
|
||||||
case @state
|
|
||||||
when :idle
|
|
||||||
transition(:open)
|
|
||||||
when :closed
|
|
||||||
transition(:idle)
|
|
||||||
transition(:open)
|
|
||||||
end
|
|
||||||
resolve if @queries.empty?
|
|
||||||
end
|
|
||||||
|
|
||||||
def to_io
|
def to_io
|
||||||
@io.to_io
|
@io.to_io
|
||||||
end
|
end
|
||||||
@ -110,6 +95,14 @@ module HTTPX
|
|||||||
end
|
end
|
||||||
|
|
||||||
def interests
|
def interests
|
||||||
|
case @state
|
||||||
|
when :idle
|
||||||
|
transition(:open)
|
||||||
|
when :closed
|
||||||
|
transition(:idle)
|
||||||
|
transition(:open)
|
||||||
|
end
|
||||||
|
|
||||||
!@write_buffer.empty? || @queries.empty? ? :w : :r
|
!@write_buffer.empty? || @queries.empty? ? :w : :r
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -279,8 +272,11 @@ module HTTPX
|
|||||||
return unless @state == :idle
|
return unless @state == :idle
|
||||||
|
|
||||||
build_socket
|
build_socket
|
||||||
|
|
||||||
@io.connect
|
@io.connect
|
||||||
return unless @io.connected?
|
return unless @io.connected?
|
||||||
|
|
||||||
|
resolve if @queries.empty?
|
||||||
when :closed
|
when :closed
|
||||||
return unless @state == :open
|
return unless @state == :open
|
||||||
|
|
||||||
|
@ -84,16 +84,19 @@ class HTTPX::Selector
|
|||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
READ_INTERESTS = %i[r rw].freeze
|
||||||
|
WRITE_INTERESTS = %i[w rw].freeze
|
||||||
|
|
||||||
def select_many(interval)
|
def select_many(interval)
|
||||||
begin
|
begin
|
||||||
r = nil
|
r = nil
|
||||||
w = nil
|
w = nil
|
||||||
|
|
||||||
@selectables.each_key do |io|
|
@selectables.each_key do |io|
|
||||||
io.connect if io.connecting?
|
interests = io.interests
|
||||||
|
|
||||||
(r ||= []) << io if io.interests == :r || io.interests == :rw
|
(r ||= []) << io if READ_INTERESTS.include?(interests)
|
||||||
(w ||= []) << io if io.interests == :w || io.interests == :rw
|
(w ||= []) << io if WRITE_INTERESTS.include?(interests)
|
||||||
end
|
end
|
||||||
|
|
||||||
readers, writers = IO.select(r, w, nil, interval)
|
readers, writers = IO.select(r, w, nil, interval)
|
||||||
@ -125,8 +128,6 @@ class HTTPX::Selector
|
|||||||
def select_one(interval)
|
def select_one(interval)
|
||||||
io, monitor = @selectables.first
|
io, monitor = @selectables.first
|
||||||
|
|
||||||
io.connect if io.connecting?
|
|
||||||
|
|
||||||
result = case io.interests
|
result = case io.interests
|
||||||
when :r then io.to_io.wait_readable(interval)
|
when :r then io.to_io.wait_readable(interval)
|
||||||
when :w then io.to_io.wait_writable(interval)
|
when :w then io.to_io.wait_writable(interval)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user