Changeset 33748 in project


Ignore:
Timestamp:
11/19/16 15:00:29 (8 months ago)
Author:
sjamaan
Message:

http-client: Close the connection before discarding it, if maximum is reached!

File:
1 edited

Legend:

Unmodified
Added
Removed
  • release/4/http-client/trunk/http-client.scm

    r33747 r33748  
    198198;; If max-idle-connections is not yet reached, add it to the pool.  We
    199199;; add it to the end because it is the freshest one.  This ensures
    200 ;; we'll re-use the oldest first, trying to keep them all alive.
     200;; we'll re-use the oldest first, trying to keep them all alive.  If
     201;; the maximum is reached, close and discard the connection.
    201202(define (maybe-add-idle-connection! uri con)
    202203  (with-mutex
     
    204205   (lambda ()
    205206     (let ((count (mutex-specific *idle-connections-mutex*)))
    206        (when (< count (max-idle-connections))
    207          (cond ((hash-table-ref/default *idle-connections* uri #f) =>
    208                 (lambda (oldest-con)
    209                   (let lp ((head (cdr oldest-con)))
    210                     (if (eq? (cdr head) oldest-con) ; last?
    211                         (set-cdr! head (cons con oldest-con))
    212                         (lp (cdr head))))))
    213                (else
    214                 (let ((new-con (list con)))
    215                   (set-cdr! new-con new-con) ; (circular-list con)
    216                   (hash-table-set! *idle-connections* uri new-con))))
    217          (mutex-specific-set! *idle-connections-mutex* (add1 count)))))))
     207       (if (< count (max-idle-connections))
     208           (begin
     209             (cond ((hash-table-ref/default *idle-connections* uri #f) =>
     210                    (lambda (oldest-con)
     211                      (let lp ((head (cdr oldest-con)))
     212                        (if (eq? (cdr head) oldest-con) ; last?
     213                            (set-cdr! head (cons con oldest-con))
     214                            (lp (cdr head))))))
     215                   (else
     216                    (let ((new-con (list con)))
     217                      (set-cdr! new-con new-con) ; (circular-list con)
     218                      (hash-table-set! *idle-connections* uri new-con))))
     219             (mutex-specific-set! *idle-connections-mutex* (add1 count)))
     220           (close-connection! uri con))))))
    218221
    219222
Note: See TracChangeset for help on using the changeset viewer.