mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-18 15:55:36 +00:00
Bug 1187137 (part 13) - Replace nsBaseHashtable::Enumerate() calls in netwerk/protocol/ with iterators. r=valentin.
--HG-- extra : rebase_source : 67a9afc30e75e7676a935e95057af28ed2623354
This commit is contained in:
parent
f852272c8b
commit
2de1cd4d7a
@ -535,25 +535,21 @@ nsHttpConnectionMgr::UpdateRequestTokenBucket(EventTokenBucket *aBucket)
|
||||
0, aBucket);
|
||||
}
|
||||
|
||||
PLDHashOperator
|
||||
nsHttpConnectionMgr::RemoveDeadConnections(const nsACString &key,
|
||||
nsAutoPtr<nsConnectionEntry> &ent,
|
||||
void *aArg)
|
||||
{
|
||||
if (ent->mIdleConns.Length() == 0 &&
|
||||
ent->mActiveConns.Length() == 0 &&
|
||||
ent->mHalfOpens.Length() == 0 &&
|
||||
ent->mPendingQ.Length() == 0) {
|
||||
return PL_DHASH_REMOVE;
|
||||
}
|
||||
return PL_DHASH_NEXT;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsHttpConnectionMgr::ClearConnectionHistory()
|
||||
{
|
||||
MOZ_ASSERT(PR_GetCurrentThread() == gSocketThread);
|
||||
mCT.Enumerate(RemoveDeadConnections, nullptr);
|
||||
|
||||
for (auto iter = mCT.Iter(); !iter.Done(); iter.Next()) {
|
||||
nsAutoPtr<nsConnectionEntry>& ent = iter.Data();
|
||||
if (ent->mIdleConns.Length() == 0 &&
|
||||
ent->mActiveConns.Length() == 0 &&
|
||||
ent->mHalfOpens.Length() == 0 &&
|
||||
ent->mPendingQ.Length() == 0) {
|
||||
iter.Remove();
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@ -2736,69 +2732,67 @@ nsHttpConnectionMgr::TimeoutTick()
|
||||
// Set it to the max value here, and the TimeoutTickCB()s can
|
||||
// reduce it to their local needs.
|
||||
mTimeoutTickNext = 3600; // 1hr
|
||||
mCT.Enumerate(TimeoutTickCB, this);
|
||||
|
||||
for (auto iter = mCT.Iter(); !iter.Done(); iter.Next()) {
|
||||
nsAutoPtr<nsConnectionEntry>& ent = iter.Data();
|
||||
|
||||
LOG(("nsHttpConnectionMgr::TimeoutTickCB() this=%p host=%s "
|
||||
"idle=%d active=%d half-len=%d pending=%d\n",
|
||||
this, ent->mConnInfo->Origin(), ent->mIdleConns.Length(),
|
||||
ent->mActiveConns.Length(), ent->mHalfOpens.Length(),
|
||||
ent->mPendingQ.Length()));
|
||||
|
||||
// First call the tick handler for each active connection.
|
||||
PRIntervalTime now = PR_IntervalNow();
|
||||
for (uint32_t index = 0; index < ent->mActiveConns.Length(); ++index) {
|
||||
uint32_t connNextTimeout =
|
||||
ent->mActiveConns[index]->ReadTimeoutTick(now);
|
||||
mTimeoutTickNext = std::min(mTimeoutTickNext, connNextTimeout);
|
||||
}
|
||||
|
||||
// Now check for any stalled half open sockets.
|
||||
if (ent->mHalfOpens.Length()) {
|
||||
TimeStamp now = TimeStamp::Now();
|
||||
double maxConnectTime_ms = gHttpHandler->ConnectTimeout();
|
||||
|
||||
for (uint32_t index = ent->mHalfOpens.Length(); index > 0; ) {
|
||||
index--;
|
||||
|
||||
nsHalfOpenSocket *half = ent->mHalfOpens[index];
|
||||
double delta = half->Duration(now);
|
||||
// If the socket has timed out, close it so the waiting
|
||||
// transaction will get the proper signal.
|
||||
if (delta > maxConnectTime_ms) {
|
||||
LOG(("Force timeout of half open to %s after %.2fms.\n",
|
||||
ent->mConnInfo->HashKey().get(), delta));
|
||||
if (half->SocketTransport()) {
|
||||
half->SocketTransport()->Close(NS_ERROR_ABORT);
|
||||
}
|
||||
if (half->BackupTransport()) {
|
||||
half->BackupTransport()->Close(NS_ERROR_ABORT);
|
||||
}
|
||||
}
|
||||
|
||||
// If this half open hangs around for 5 seconds after we've
|
||||
// closed() it then just abandon the socket.
|
||||
if (delta > maxConnectTime_ms + 5000) {
|
||||
LOG(("Abandon half open to %s after %.2fms.\n",
|
||||
ent->mConnInfo->HashKey().get(), delta));
|
||||
half->Abandon();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (ent->mHalfOpens.Length()) {
|
||||
mTimeoutTickNext = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (mTimeoutTick) {
|
||||
mTimeoutTickNext = std::max(mTimeoutTickNext, 1U);
|
||||
mTimeoutTick->SetDelay(mTimeoutTickNext * 1000);
|
||||
}
|
||||
}
|
||||
|
||||
PLDHashOperator
|
||||
nsHttpConnectionMgr::TimeoutTickCB(const nsACString &key,
|
||||
nsAutoPtr<nsConnectionEntry> &ent,
|
||||
void *closure)
|
||||
{
|
||||
nsHttpConnectionMgr *self = (nsHttpConnectionMgr *) closure;
|
||||
|
||||
LOG(("nsHttpConnectionMgr::TimeoutTickCB() this=%p host=%s "
|
||||
"idle=%d active=%d half-len=%d pending=%d\n",
|
||||
self, ent->mConnInfo->Origin(), ent->mIdleConns.Length(),
|
||||
ent->mActiveConns.Length(), ent->mHalfOpens.Length(),
|
||||
ent->mPendingQ.Length()));
|
||||
|
||||
// first call the tick handler for each active connection
|
||||
PRIntervalTime now = PR_IntervalNow();
|
||||
for (uint32_t index = 0; index < ent->mActiveConns.Length(); ++index) {
|
||||
uint32_t connNextTimeout = ent->mActiveConns[index]->ReadTimeoutTick(now);
|
||||
self->mTimeoutTickNext = std::min(self->mTimeoutTickNext, connNextTimeout);
|
||||
}
|
||||
|
||||
// now check for any stalled half open sockets
|
||||
if (ent->mHalfOpens.Length()) {
|
||||
TimeStamp now = TimeStamp::Now();
|
||||
double maxConnectTime = gHttpHandler->ConnectTimeout(); /* in milliseconds */
|
||||
|
||||
for (uint32_t index = ent->mHalfOpens.Length(); index > 0; ) {
|
||||
index--;
|
||||
|
||||
nsHalfOpenSocket *half = ent->mHalfOpens[index];
|
||||
double delta = half->Duration(now);
|
||||
// If the socket has timed out, close it so the waiting transaction
|
||||
// will get the proper signal
|
||||
if (delta > maxConnectTime) {
|
||||
LOG(("Force timeout of half open to %s after %.2fms.\n",
|
||||
ent->mConnInfo->HashKey().get(), delta));
|
||||
if (half->SocketTransport())
|
||||
half->SocketTransport()->Close(NS_ERROR_ABORT);
|
||||
if (half->BackupTransport())
|
||||
half->BackupTransport()->Close(NS_ERROR_ABORT);
|
||||
}
|
||||
|
||||
// If this half open hangs around for 5 seconds after we've closed() it
|
||||
// then just abandon the socket.
|
||||
if (delta > maxConnectTime + 5000) {
|
||||
LOG(("Abandon half open to %s after %.2fms.\n",
|
||||
ent->mConnInfo->HashKey().get(), delta));
|
||||
half->Abandon();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (ent->mHalfOpens.Length()) {
|
||||
self->mTimeoutTickNext = 1;
|
||||
}
|
||||
return PL_DHASH_NEXT;
|
||||
}
|
||||
|
||||
// GetOrCreateConnectionEntry finds a ent for a particular CI for use in
|
||||
// dispatching a transaction according to these rules
|
||||
// 1] use an ent that matches the ci that can be dispatched immediately
|
||||
|
@ -627,15 +627,8 @@ private:
|
||||
//
|
||||
nsClassHashtable<nsCStringHashKey, nsConnectionEntry> mCT;
|
||||
|
||||
static PLDHashOperator RemoveDeadConnections(const nsACString &key,
|
||||
nsAutoPtr<nsConnectionEntry> &ent,
|
||||
void *aArg);
|
||||
|
||||
// Read Timeout Tick handlers
|
||||
void TimeoutTick();
|
||||
static PLDHashOperator TimeoutTickCB(const nsACString &key,
|
||||
nsAutoPtr<nsConnectionEntry> &ent,
|
||||
void *closure);
|
||||
|
||||
// For diagnostics
|
||||
void OnMsgPrintDiagnostics(int32_t, ARefBase *);
|
||||
|
Loading…
Reference in New Issue
Block a user