lib/httpx/connection.rb in httpx-0.12.0 vs lib/httpx/connection.rb in httpx-0.13.0
- old
+ new
@@ -69,10 +69,12 @@
end
@inflight = 0
@keep_alive_timeout = options.timeout.keep_alive_timeout
@keep_alive_timer = nil
+
+ self.addresses = options.addresses if options.addresses
end
# this is a semi-private method, to be used by the resolver
# to initiate the io object.
def addresses=(addrs)
@@ -103,10 +105,12 @@
def mergeable?(connection)
return false if @state == :closing || @state == :closed || !@io
return false if exhausted?
+ return false unless connection.addresses
+
!(@io.addresses & connection.addresses).empty? && @options == connection.options
end
# coalescable connections need to be mergeable!
# but internally, #mergeable? is called before #coalescable?
@@ -470,34 +474,34 @@
if @total_timeout
@total_timeout.cancel
remove_instance_variable(:@total_timeout)
end
- @io.close if @io
- @read_buffer.clear
- if @keep_alive_timer
- @keep_alive_timer.cancel
- remove_instance_variable(:@keep_alive_timer)
- end
-
- remove_instance_variable(:@timeout) if defined?(@timeout)
+ purge_after_closed
when :already_open
nextstate = :open
send_pending
end
@state = nextstate
- rescue Errno::EHOSTUNREACH
- # at this point, all addresses from the IO object have failed
- reset
- emit(:unreachable)
- throw(:jump_tick)
rescue Errno::ECONNREFUSED,
Errno::EADDRNOTAVAIL,
+ Errno::EHOSTUNREACH,
TLSError => e
# connect errors, exit gracefully
handle_error(e)
@state = :closed
emit(:close)
+ end
+
+ def purge_after_closed
+ @io.close if @io
+ @read_buffer.clear
+ if @keep_alive_timer
+ @keep_alive_timer.cancel
+ remove_instance_variable(:@keep_alive_timer)
+ end
+
+ remove_instance_variable(:@timeout) if defined?(@timeout)
end
def handle_response
@inflight -= 1
return unless @inflight.zero?