mirror of
https://github.com/HoneyryderChuck/httpx.git
synced 2025-08-10 00:01:27 -04:00
made the timeout logic around connections more simple
This commit is contained in:
parent
9ec6be0279
commit
57a85de999
@ -46,8 +46,6 @@ module HTTPX
|
||||
|
||||
attr_reader :origin, :state, :pending, :options
|
||||
|
||||
attr_reader :timeout
|
||||
|
||||
def initialize(type, uri, options)
|
||||
@type = type
|
||||
@origins = [uri.origin]
|
||||
@ -188,7 +186,6 @@ module HTTPX
|
||||
end
|
||||
|
||||
def call
|
||||
@timeout = @timeout_threshold
|
||||
case @state
|
||||
when :closed
|
||||
return
|
||||
@ -202,6 +199,14 @@ module HTTPX
|
||||
nil
|
||||
end
|
||||
|
||||
def timeout
|
||||
return @timeout if defined?(@timeout)
|
||||
|
||||
return @options.timeout.connect_timeout if @state == :idle
|
||||
|
||||
@options.timeout.operation_timeout
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def consume
|
||||
@ -289,8 +294,8 @@ module HTTPX
|
||||
transition(:open)
|
||||
end
|
||||
end
|
||||
parser.on(:timeout) do |timeout|
|
||||
@timeout = timeout
|
||||
parser.on(:timeout) do |tout|
|
||||
@timeout = tout
|
||||
end
|
||||
parser.on(:error) do |request, ex|
|
||||
case ex
|
||||
@ -307,8 +312,6 @@ module HTTPX
|
||||
case nextstate
|
||||
when :idle
|
||||
@error = nil
|
||||
@timeout_threshold = @options.timeout.connect_timeout
|
||||
@timeout = @timeout_threshold
|
||||
when :open
|
||||
return if @state == :closed
|
||||
|
||||
@ -316,8 +319,6 @@ module HTTPX
|
||||
return unless @io.connected?
|
||||
|
||||
send_pending
|
||||
@timeout_threshold = @options.timeout.operation_timeout
|
||||
@timeout = @timeout_threshold
|
||||
emit(:open)
|
||||
when :closing
|
||||
return unless @state == :open
|
||||
@ -327,11 +328,10 @@ module HTTPX
|
||||
|
||||
@io.close
|
||||
@read_buffer.clear
|
||||
remove_instance_variable(:@timeout) if defined?(@timeout)
|
||||
when :already_open
|
||||
nextstate = :open
|
||||
send_pending
|
||||
@timeout_threshold = @options.timeout.operation_timeout
|
||||
@timeout = @timeout_threshold
|
||||
end
|
||||
@state = nextstate
|
||||
rescue Errno::EHOSTUNREACH
|
||||
|
Loading…
x
Reference in New Issue
Block a user