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.



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

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)

:nodoc:



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

def cert_files
  @cert_files
end

#proxy_uriObject (readonly)

:nodoc:



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

def proxy_uri
  @proxy_uri
end

Instance Method Details

#checkin(connection) ⇒ Object



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

def checkin(connection)
  @queue.push connection
end

#checkoutObject



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

def checkout
  @queue.pop || make_connection
end

#close_allObject



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

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