diff options
Diffstat (limited to 'lib/rubygems/request/http_pool.rb')
| -rw-r--r-- | lib/rubygems/request/http_pool.rb | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/lib/rubygems/request/http_pool.rb b/lib/rubygems/request/http_pool.rb index bfcd15399d..468502ca6b 100644 --- a/lib/rubygems/request/http_pool.rb +++ b/lib/rubygems/request/http_pool.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + ## # A connection "pool" that only manages one connection for now. Provides # thread safe `checkout` and `checkin` methods. The pool consists of one @@ -8,29 +9,32 @@ class Gem::Request::HTTPPool # :nodoc: attr_reader :cert_files, :proxy_uri - def initialize http_args, cert_files, proxy_uri + def initialize(http_args, cert_files, proxy_uri, pool_size) @http_args = http_args @cert_files = cert_files @proxy_uri = proxy_uri - @queue = SizedQueue.new 1 - @queue << nil + @pool_size = pool_size + + @queue = Thread::SizedQueue.new @pool_size + setup_queue end def checkout @queue.pop || make_connection end - def checkin connection + def checkin(connection) @queue.push connection end def close_all until @queue.empty? - if connection = @queue.pop(true) and connection.started? + if (connection = @queue.pop(true)) && connection.started? connection.finish end end - @queue.push(nil) + + setup_queue end private @@ -39,10 +43,12 @@ class Gem::Request::HTTPPool # :nodoc: setup_connection Gem::Request::ConnectionPools.client.new(*@http_args) end - def setup_connection connection + def setup_connection(connection) connection.start connection end + def setup_queue + @pool_size.times { @queue.push(nil) } + end end - |
