From 24e661a77497cfff9e154fb5f224e2a68d484268 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Tue, 3 Nov 2015 17:00:30 -0800 Subject: [PATCH] Bug 1187137 (part 2) - Replace nsBaseHashtable::Enumerate() calls in netwerk/protocol/ with iterators. r=michal. --- netwerk/protocol/http/nsHttpConnectionMgr.cpp | 47 ++++++++----------- netwerk/protocol/http/nsHttpConnectionMgr.h | 1 - 2 files changed, 20 insertions(+), 28 deletions(-) diff --git a/netwerk/protocol/http/nsHttpConnectionMgr.cpp b/netwerk/protocol/http/nsHttpConnectionMgr.cpp index 7fc5b640b12..e8a072897d9 100644 --- a/netwerk/protocol/http/nsHttpConnectionMgr.cpp +++ b/netwerk/protocol/http/nsHttpConnectionMgr.cpp @@ -847,31 +847,6 @@ nsHttpConnectionMgr::ProcessAllTransactionsCB(const nsACString &key, return PL_DHASH_NEXT; } -// If the global number of connections is preventing the opening of -// new connections to a host without idle connections, then -// close them regardless of their TTL -PLDHashOperator -nsHttpConnectionMgr::PurgeExcessIdleConnectionsCB(const nsACString &key, - nsAutoPtr &ent, - void *closure) -{ - nsHttpConnectionMgr *self = (nsHttpConnectionMgr *) closure; - - while (self->mNumIdleConns + self->mNumActiveConns + 1 >= self->mMaxConns) { - if (!ent->mIdleConns.Length()) { - // There are no idle conns left in this connection entry - return PL_DHASH_NEXT; - } - nsHttpConnection *conn = ent->mIdleConns[0]; - ent->mIdleConns.RemoveElementAt(0); - conn->Close(NS_ERROR_ABORT); - NS_RELEASE(conn); - self->mNumIdleConns--; - self->ConditionallyStopPruneDeadConnectionsTimer(); - } - return PL_DHASH_STOP; -} - // If the global number of connections is preventing the opening of // new connections to a host without idle connections, then // close any spdy asap @@ -1469,8 +1444,26 @@ nsHttpConnectionMgr::MakeNewConnection(nsConnectionEntry *ent, // beacuse we have already determined there are no idle connections // to our destination - if ((mNumIdleConns + mNumActiveConns + 1 >= mMaxConns) && mNumIdleConns) - mCT.Enumerate(PurgeExcessIdleConnectionsCB, this); + if ((mNumIdleConns + mNumActiveConns + 1 >= mMaxConns) && mNumIdleConns) { + // If the global number of connections is preventing the opening of new + // connections to a host without idle connections, then close them + // regardless of their TTL. + auto iter = mCT.Iter(); + while (mNumIdleConns + mNumActiveConns + 1 >= mMaxConns && + !iter.Done()) { + nsAutoPtr &ent = iter.Data(); + if (!ent->mIdleConns.Length()) { + iter.Next(); + continue; + } + nsHttpConnection *conn = ent->mIdleConns[0]; + ent->mIdleConns.RemoveElementAt(0); + conn->Close(NS_ERROR_ABORT); + NS_RELEASE(conn); + mNumIdleConns--; + ConditionallyStopPruneDeadConnectionsTimer(); + } + } if ((mNumIdleConns + mNumActiveConns + 1 >= mMaxConns) && mNumActiveConns && gHttpHandler->IsSpdyEnabled()) diff --git a/netwerk/protocol/http/nsHttpConnectionMgr.h b/netwerk/protocol/http/nsHttpConnectionMgr.h index e52b67ca864..df30131e294 100644 --- a/netwerk/protocol/http/nsHttpConnectionMgr.h +++ b/netwerk/protocol/http/nsHttpConnectionMgr.h @@ -514,7 +514,6 @@ private: static PLDHashOperator PruneDeadConnectionsCB(const nsACString &, nsAutoPtr &, void *); static PLDHashOperator ShutdownPassCB(const nsACString &, nsAutoPtr &, void *); - static PLDHashOperator PurgeExcessIdleConnectionsCB(const nsACString &, nsAutoPtr &, void *); static PLDHashOperator PurgeExcessSpdyConnectionsCB(const nsACString &, nsAutoPtr &, void *); static PLDHashOperator ClosePersistentConnectionsCB(const nsACString &, nsAutoPtr &, void *); static PLDHashOperator VerifyTrafficCB(const nsACString &, nsAutoPtr &, void *);