implemented Connection#exhausted?

an exhausted connection can't service more requests, therefore is
unmatchable and can't enqueue more requests to the parser.
This commit is contained in:
HoneyryderChuck 2020-03-07 00:26:45 +00:00
parent ad49df8b34
commit 1ad91d898e
3 changed files with 16 additions and 1 deletions

View File

@ -80,6 +80,7 @@ module HTTPX
def match?(uri, options)
return false if @state == :closing || @state == :closed
return false if exhausted?
(
(
@origins.include?(uri.origin) &&
@ -95,6 +96,8 @@ module HTTPX
def mergeable?(connection)
return false if @state == :closing || @state == :closed || !@io
return false if exhausted?
!(@io.addresses & connection.addresses).empty? && @options == connection.options
end
@ -213,6 +216,10 @@ module HTTPX
private
def exhausted?
@parser && parser.exhausted?
end
def consume
catch(:called) do
dread

View File

@ -31,6 +31,10 @@ module HTTPX
emit(:close)
end
def exhausted?
!@max_requests.positive?
end
def empty?
# this means that for every request there's an available
# partial response, so there are no in-flight requests waiting.

View File

@ -35,11 +35,15 @@ module HTTPX
@connection.state == :closed || @streams.empty?
end
def exhausted?
@connection.active_stream_count >= @max_concurrent_requests
end
def <<(data)
@connection << data
end
def send(request, **)
def send(request)
if !@handshake_completed ||
@streams.size >= @max_concurrent_requests
@pending << request