Ticket #3420: updates.diff

File updates.diff, 2.6 KB (added by c00w, 3 years ago)

Fix for MaxConnections and the Boolean issue

  • client.py

     
    627627        SSL context objects for any SSL connections the agent needs to make. 
    628628 
    629629    @ivar persistent: Set to C{True} when you use HTTP persistent connecton. 
    630     @type persistent: Boolean 
     630    @type persistent: C{bool} 
    631631 
    632     @ivar maxConnections: Max number of HTTP connections per a server.  The 
    633         default value is 1.  This is effective only when the 
     632    @ivar maxConnectionsPerHostName: Max number of HTTP connections per a server.  The 
     633        default value is 2.  This is effective only when the 
    634634        C{self.persistent} is C{True}. 
    635635        RFC 2616 says "A single-user client SHOULD NOT maintain more than 2 
    636636        connections with any server or proxy." 
    637     @type maxConnections: C{int} 
     637    @type maxConnectionsPerHostName: C{int} 
    638638 
    639639    @ivar _semaphores: A dictioinary mapping a tuple (scheme, host, port) 
    640640        to an instance of L{DeferredSemaphore}.  It is used to limit the 
     
    647647    @since: 9.0 
    648648    """ 
    649649    _protocol = HTTP11ClientProtocol 
    650     maxConnections = 1 
     650    maxConnectionsPerHostName = 2 
    651651 
    652652    def __init__(self, reactor, contextFactory=WebClientContextFactory(), 
    653                  persistent=False): 
     653                 persistent=False, maxConnectionsPerHostName=2): 
    654654        self._reactor = reactor 
    655655        self._contextFactory = contextFactory 
    656656        self.persistent = persistent 
     657        self.maxConnectionsPerHostName = maxConnectionsPerHostName 
    657658        self._semaphores = {} 
    658659        self._protocolCache = {} 
    659660 
     
    739740        if self.persistent: 
    740741            sem = self._semaphores.get((scheme, host, port)) 
    741742            if sem is None: 
    742                 sem = defer.DeferredSemaphore(self.maxConnections) 
     743                sem = defer.DeferredSemaphore(self.maxConnectionsPerHostName) 
    743744                self._semaphores[scheme, host, port] = sem 
    744745            return sem.run(self._request, method, scheme, host, port, path, 
    745746                           headers, bodyProducer) 
     
    808809                # Previous connection is unavailable. 
    809810                if f.check(ResponseFailed): 
    810811                    for reason in f.value.reasons: 
    811                         if (isinstance(reason, failure.Failure) and  
     812                        if (isinstance(reason, failure.Failure) and 
    812813                            isinstance(reason.value, ConnectionDone)): 
    813814                            # Maybe timeout has been exeeded before I send 
    814815                            # the request. So I retry again.