Class: Gem::Request::HTTPPool

Inherits:
Object
  • Object
show all
Defined in:
lib/rubygems/request/http_pool.rb

Overview

A connection “pool” that only manages one connection for now. Provides thread safe ‘checkout` and `checkin` methods. The pool consists of one connection that corresponds to `http_args`. This class is private, do not use it.

Direct Known Subclasses

HTTPSPool

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(http_args, cert_files, proxy_uri) ⇒ HTTPPool

Returns a new instance of HTTPPool.



12
13
14
15
16
17
18
# File 'lib/rubygems/request/http_pool.rb', line 12

def initialize(http_args, cert_files, proxy_uri)
  @http_args  = http_args
  @cert_files = cert_files
  @proxy_uri  = proxy_uri
  @queue      = SizedQueue.new 1
  @queue << nil
end

Instance Attribute Details

#cert_filesObject (readonly)

Returns the value of attribute cert_files



10
11
12
# File 'lib/rubygems/request/http_pool.rb', line 10

def cert_files
  @cert_files
end

#proxy_uriObject (readonly)

Returns the value of attribute proxy_uri



10
11
12
# File 'lib/rubygems/request/http_pool.rb', line 10

def proxy_uri
  @proxy_uri
end

Instance Method Details

#checkin(connection) ⇒ Object



24
25
26
# File 'lib/rubygems/request/http_pool.rb', line 24

def checkin(connection)
  @queue.push connection
end

#checkoutObject



20
21
22
# File 'lib/rubygems/request/http_pool.rb', line 20

def checkout
  @queue.pop || make_connection
end

#close_allObject



28
29
30
31
32
33
34
35
# File 'lib/rubygems/request/http_pool.rb', line 28

def close_all
  until @queue.empty?
    if connection = @queue.pop(true) and connection.started?
      connection.finish
    end
  end
  @queue.push(nil)
end