Bug 1672520 - Make member variable of PendingTransactionInfo private r=necko-reviewers,valentin

Differential Revision: https://phabricator.services.mozilla.com/D94509
This commit is contained in:
Dragana Damjanovic 2020-10-31 18:26:42 +00:00
parent a0deb61454
commit c824810ab5
9 changed files with 214 additions and 160 deletions

View File

@ -487,7 +487,8 @@ void ConnectionEntry::VerifyTraffic() {
}
}
void ConnectionEntry::InsertIntoIdleConnections_internal(nsHttpConnection* conn) {
void ConnectionEntry::InsertIntoIdleConnections_internal(
nsHttpConnection* conn) {
uint32_t idx;
for (idx = 0; idx < mIdleConns.Length(); idx++) {
nsHttpConnection* idleConn = mIdleConns[idx];
@ -553,12 +554,13 @@ void ConnectionEntry::MakeAllDontReuseExcept(HttpConnectionBase* conn) {
bool ConnectionEntry::FindConnToClaim(
PendingTransactionInfo* pendingTransInfo) {
nsHttpTransaction* trans = pendingTransInfo->mTransaction;
nsHttpTransaction* trans = pendingTransInfo->Transaction();
uint32_t halfOpenLength = HalfOpensLength();
for (uint32_t i = 0; i < halfOpenLength; i++) {
auto halfOpen = mHalfOpens[i];
if (halfOpen->AcceptsTransaction(trans) && halfOpen->Claim()) {
if (halfOpen->AcceptsTransaction(trans) &&
pendingTransInfo->TryClaimingHalfOpen(halfOpen)) {
// We've found a speculative connection or a connection that
// is free to be used in the half open list.
// A free to be used connection is a connection that was
@ -568,8 +570,7 @@ bool ConnectionEntry::FindConnToClaim(
("ConnectionEntry::FindConnToClaim [ci = %s]\n"
"Found a speculative or a free-to-use half open connection\n",
mConnInfo->HashKey().get()));
pendingTransInfo->mHalfOpen = do_GetWeakReference(
static_cast<nsISupportsWeakReference*>(mHalfOpens[i]));
// return OK because we have essentially opened a new connection
// by converting a speculative half-open to general use
return true;
@ -582,16 +583,11 @@ bool ConnectionEntry::FindConnToClaim(
if (trans->Caps() & NS_HTTP_ALLOW_KEEPALIVE) {
uint32_t activeLength = mActiveConns.Length();
for (uint32_t i = 0; i < activeLength; i++) {
nsAHttpTransaction* activeTrans = mActiveConns[i]->Transaction();
NullHttpTransaction* nullTrans =
activeTrans ? activeTrans->QueryNullTransaction() : nullptr;
if (nullTrans && nullTrans->Claim()) {
if (pendingTransInfo->TryClaimingActiveConn(mActiveConns[i])) {
LOG(
("ConnectionEntry::FindConnectingSocket [ci = %s] "
"Claiming a null transaction for later use\n",
mConnInfo->HashKey().get()));
pendingTransInfo->mActiveConn = do_GetWeakReference(
static_cast<nsISupportsWeakReference*>(mActiveConns[i]));
return true;
}
}

View File

@ -516,8 +516,7 @@ HalfOpenSocket::OnOutputStreamReady(nsIAsyncOutputStream* out) {
if (trans && trans->QueryHttpTransaction()) {
RefPtr<PendingTransactionInfo> pendingTransInfo =
new PendingTransactionInfo(trans->QueryHttpTransaction());
pendingTransInfo->mHalfOpen =
do_GetWeakReference(static_cast<nsISupportsWeakReference*>(this));
pendingTransInfo->AddHalfOpen(this);
mEnt->InsertTransaction(pendingTransInfo, true);
}
if (mEnt->mUseFastOpen) {
@ -745,8 +744,7 @@ void HalfOpenSocket::SetFastOpenConnected(nsresult aError, bool aWillRetry) {
if (trans && trans->QueryHttpTransaction()) {
RefPtr<PendingTransactionInfo> pendingTransInfo =
new PendingTransactionInfo(trans->QueryHttpTransaction());
pendingTransInfo->mHalfOpen =
do_GetWeakReference(static_cast<nsISupportsWeakReference*>(this));
pendingTransInfo->AddHalfOpen(this);
mEnt->InsertTransaction(pendingTransInfo, true);
}
// We are doing a restart without fast open, so the easiest way is to
@ -1000,10 +998,10 @@ nsresult HalfOpenSocket::SetupConn(nsIAsyncOutputStream* out, bool aFastOpen) {
// used also for the first transaction, therefore we need to create
// ConnectionHandle here.
RefPtr<ConnectionHandle> handle = new ConnectionHandle(conn);
pendingTransInfo->mTransaction->SetConnection(handle);
pendingTransInfo->Transaction()->SetConnection(handle);
}
rv = gHttpHandler->ConnMgr()->DispatchTransaction(
mEnt, pendingTransInfo->mTransaction, conn);
mEnt, pendingTransInfo->Transaction(), conn);
} else {
// this transaction was dispatched off the pending q before all the
// sockets established themselves.

View File

@ -0,0 +1,135 @@
/* vim:t ts=4 sw=2 sts=2 et cin: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// HttpLog.h should generally be included first
#include "HttpLog.h"
#include "PendingTransactionInfo.h"
#include "HalfOpenSocket.h"
// Log on level :5, instead of default :4.
#undef LOG
#define LOG(args) LOG5(args)
#undef LOG_ENABLED
#define LOG_ENABLED() LOG5_ENABLED()
namespace mozilla {
namespace net {
PendingTransactionInfo::~PendingTransactionInfo() {
if (mHalfOpen) {
RefPtr<HalfOpenSocket> halfOpen = do_QueryReferent(mHalfOpen);
LOG(
("PendingTransactionInfo::PendingTransactionInfo "
"[trans=%p halfOpen=%p]",
mTransaction.get(), halfOpen.get()));
if (halfOpen) {
halfOpen->Unclaim();
}
mHalfOpen = nullptr;
} else if (mActiveConn) {
RefPtr<HttpConnectionBase> activeConn = do_QueryReferent(mActiveConn);
if (activeConn && activeConn->Transaction() &&
activeConn->Transaction()->IsNullTransaction()) {
NullHttpTransaction* nullTrans =
activeConn->Transaction()->QueryNullTransaction();
nullTrans->Unclaim();
LOG((
"PendingTransactionInfo::PendingTransactionInfo - mark %p unclaimed.",
activeConn.get()));
}
}
}
bool PendingTransactionInfo::IsAlreadyClaimedInitializingConn() {
LOG(
("PendingTransactionInfo::IsAlreadyClaimedInitializingConn "
"[trans=%p, halfOpen=%p, activeConn=%p]\n",
mTransaction.get(), mHalfOpen.get(), mActiveConn.get()));
// When this transaction has already established a half-open
// connection, we want to prevent any duplicate half-open
// connections from being established and bound to this
// transaction. Allow only use of an idle persistent connection
// (if found) for transactions referred by a half-open connection.
bool alreadyHalfOpenOrWaitingForTLS = false;
if (mHalfOpen) {
MOZ_ASSERT(!mActiveConn);
RefPtr<HalfOpenSocket> halfOpen = do_QueryReferent(mHalfOpen);
LOG(
("PendingTransactionInfo::IsAlreadyClaimedInitializingConn "
"[trans=%p, halfOpen=%p]\n",
mTransaction.get(), halfOpen.get()));
if (halfOpen) {
alreadyHalfOpenOrWaitingForTLS = true;
} else {
// If we have not found the halfOpen socket, remove the pointer.
mHalfOpen = nullptr;
}
} else if (mActiveConn) {
MOZ_ASSERT(!mHalfOpen);
RefPtr<HttpConnectionBase> activeConn = do_QueryReferent(mActiveConn);
LOG(
("PendingTransactionInfo::IsAlreadyClaimedInitializingConn "
"[trans=%p, activeConn=%p]\n",
mTransaction.get(), activeConn.get()));
// Check if this transaction claimed a connection that is still
// performing tls handshake with a NullHttpTransaction or it is between
// finishing tls and reclaiming (When nullTrans finishes tls handshake,
// httpConnection does not have a transaction any more and a
// ReclaimConnection is dispatched). But if an error occurred the
// connection will be closed, it will exist but CanReused will be
// false.
if (activeConn &&
((activeConn->Transaction() &&
activeConn->Transaction()->IsNullTransaction()) ||
(!activeConn->Transaction() && activeConn->CanReuse()))) {
alreadyHalfOpenOrWaitingForTLS = true;
} else {
// If we have not found the connection, remove the pointer.
mActiveConn = nullptr;
}
}
return alreadyHalfOpenOrWaitingForTLS;
}
void PendingTransactionInfo::AbandonHalfOpenAndForgetActiveConn() {
// Abandon all half-open sockets belonging to the given transaction.
RefPtr<HalfOpenSocket> half = do_QueryReferent(mHalfOpen);
if (half) {
half->Abandon();
}
mHalfOpen = nullptr;
mActiveConn = nullptr;
}
bool PendingTransactionInfo::TryClaimingHalfOpen(HalfOpenSocket* sock) {
if (sock->Claim()) {
mHalfOpen =
do_GetWeakReference(static_cast<nsISupportsWeakReference*>(sock));
return true;
}
return false;
}
bool PendingTransactionInfo::TryClaimingActiveConn(HttpConnectionBase* conn) {
nsAHttpTransaction* activeTrans = conn->Transaction();
NullHttpTransaction* nullTrans =
activeTrans ? activeTrans->QueryNullTransaction() : nullptr;
if (nullTrans && nullTrans->Claim()) {
mActiveConn =
do_GetWeakReference(static_cast<nsISupportsWeakReference*>(conn));
return true;
}
return false;
}
void PendingTransactionInfo::AddHalfOpen(HalfOpenSocket* sock) {
mHalfOpen = do_GetWeakReference(static_cast<nsISupportsWeakReference*>(sock));
}
} // namespace net
} // namespace mozilla

View File

@ -6,6 +6,8 @@
#ifndef PendingTransactionInfo_h__
#define PendingTransactionInfo_h__
#include "HalfOpenSocket.h"
namespace mozilla {
namespace net {
@ -18,13 +20,30 @@ class PendingTransactionInfo final : public ARefBase {
void PrintDiagnostics(nsCString& log);
public: // meant to be public.
// Return true if the transaction has claimed a HalfOpen socket or
// a connection in TLS handshake phase.
bool IsAlreadyClaimedInitializingConn();
void AbandonHalfOpenAndForgetActiveConn();
// Try to claim a halfOpen socket. We can only claim it if it is not
// claimed yet.
bool TryClaimingHalfOpen(HalfOpenSocket* sock);
// Similar as above, but for a ActiveConn that is performing a TLS handshake
// and has only a NullTransaction associated.
bool TryClaimingActiveConn(HttpConnectionBase* conn);
// It is similar as above, but in tihs case the halfOpen is made for this
// PendingTransactionInfo and it is already claimed.
void AddHalfOpen(HalfOpenSocket* sock);
nsHttpTransaction* Transaction() const { return mTransaction; }
private:
RefPtr<nsHttpTransaction> mTransaction;
nsWeakPtr mHalfOpen;
nsWeakPtr mActiveConn;
private:
virtual ~PendingTransactionInfo() = default;
~PendingTransactionInfo();
};
} // namespace net

View File

@ -13,6 +13,8 @@
#define LOG_ENABLED() LOG5_ENABLED()
#include "PendingTransactionQueue.h"
#include "nsHttpHandler.h"
#include "mozilla/ChaosMode.h"
namespace mozilla {
namespace net {
@ -27,7 +29,7 @@ class PendingComparator {
public:
bool Equals(const PendingTransactionInfo* aPendingTrans,
const nsAHttpTransaction* aTrans) const {
return aPendingTrans->mTransaction.get() == aTrans;
return aPendingTrans->Transaction() == aTrans;
}
};
@ -58,10 +60,10 @@ void PendingTransactionQueue::InsertTransactionNormal(
LOG(
("PendingTransactionQueue::InsertTransactionNormal"
" trans=%p, windowId=%" PRIu64 "\n",
info->mTransaction.get(),
info->mTransaction->TopLevelOuterContentWindowId()));
info->Transaction(),
info->Transaction()->TopLevelOuterContentWindowId()));
uint64_t windowId = TabIdForQueuing(info->mTransaction);
uint64_t windowId = TabIdForQueuing(info->Transaction());
nsTArray<RefPtr<PendingTransactionInfo>>* infoArray;
if (!mPendingTransactionTable.Get(windowId, &infoArray)) {
infoArray = new nsTArray<RefPtr<PendingTransactionInfo>>();
@ -83,17 +85,17 @@ void PendingTransactionQueue::InsertTransactionSorted(
// search in reverse order under the assumption that many of the
// existing transactions will have the same priority (usually 0).
nsHttpTransaction* trans = pendingTransInfo->mTransaction;
nsHttpTransaction* trans = pendingTransInfo->Transaction();
for (int32_t i = pendingQ.Length() - 1; i >= 0; --i) {
nsHttpTransaction* t = pendingQ[i]->mTransaction;
nsHttpTransaction* t = pendingQ[i]->Transaction();
if (TransactionComparator(trans, t)) {
if (ChaosMode::isActive(ChaosFeature::NetworkScheduling) ||
aInsertAsFirstForTheSamePriority) {
int32_t samePriorityCount;
for (samePriorityCount = 0; i - samePriorityCount >= 0;
++samePriorityCount) {
if (pendingQ[i - samePriorityCount]->mTransaction->Priority() !=
if (pendingQ[i - samePriorityCount]->Transaction()->Priority() !=
trans->Priority()) {
break;
}
@ -115,18 +117,18 @@ void PendingTransactionQueue::InsertTransactionSorted(
void PendingTransactionQueue::InsertTransaction(
PendingTransactionInfo* pendingTransInfo,
bool aInsertAsFirstForTheSamePriority /* = false */) {
if (pendingTransInfo->mTransaction->Caps() & NS_HTTP_URGENT_START) {
if (pendingTransInfo->Transaction()->Caps() & NS_HTTP_URGENT_START) {
LOG(
(" adding transaction to pending queue "
"[trans=%p urgent-start-count=%zu]\n",
pendingTransInfo->mTransaction.get(), mUrgentStartQ.Length() + 1));
pendingTransInfo->Transaction(), mUrgentStartQ.Length() + 1));
// put this transaction on the urgent-start queue...
InsertTransactionSorted(mUrgentStartQ, pendingTransInfo);
} else {
LOG(
(" adding transaction to pending queue "
"[trans=%p pending-count=%zu]\n",
pendingTransInfo->mTransaction.get(), PendingQueueLength() + 1));
pendingTransInfo->Transaction(), PendingQueueLength() + 1));
// put this transaction on the pending queue...
InsertTransactionNormal(pendingTransInfo);
}
@ -243,7 +245,7 @@ size_t PendingTransactionQueue::PendingQueueLength() const {
size_t PendingTransactionQueue::PendingQueueLengthForWindow(
uint64_t windowId) const {
auto *pendingQ = mPendingTransactionTable.Get(windowId);
auto* pendingQ = mPendingTransactionTable.Get(windowId);
return (pendingQ) ? pendingQ->Length() : 0;
}
@ -254,12 +256,12 @@ size_t PendingTransactionQueue::UrgentStartQueueLength() {
void PendingTransactionQueue::PrintPendingQ() {
LOG(("urgent queue ["));
for (const auto& info : mUrgentStartQ) {
LOG((" %p", info->mTransaction.get()));
LOG((" %p", info->Transaction()));
}
for (auto it = mPendingTransactionTable.Iter(); !it.Done(); it.Next()) {
LOG(("] window id = %" PRIx64 " queue [", it.Key()));
for (const auto& info : *it.UserData()) {
LOG((" %p", info->mTransaction.get()));
LOG((" %p", info->Transaction()));
}
}
LOG(("]"));
@ -270,22 +272,21 @@ void PendingTransactionQueue::Compact() {
for (auto it = mPendingTransactionTable.Iter(); !it.Done(); it.Next()) {
it.UserData()->Compact();
}
}
void PendingTransactionQueue::CancelAllTransactions(nsresult reason) {
for (const auto& pendingTransInfo : mUrgentStartQ) {
LOG(("PendingTransactionQueue::CancelAllTransactions %p\n",
pendingTransInfo->mTransaction.get()));
pendingTransInfo->mTransaction->Close(reason);
pendingTransInfo->Transaction()));
pendingTransInfo->Transaction()->Close(reason);
}
mUrgentStartQ.Clear();
for (auto it = mPendingTransactionTable.Iter(); !it.Done(); it.Next()) {
for (const auto& pendingTransInfo : *it.UserData()) {
LOG(("PendingTransactionQueue::CancelAllTransactions %p\n",
pendingTransInfo->mTransaction.get()));
pendingTransInfo->mTransaction->Close(reason);
pendingTransInfo->Transaction()));
pendingTransInfo->Transaction()->Close(reason);
}
it.UserData()->Clear();
}

View File

@ -6,6 +6,9 @@
#ifndef PendingTransactionQueue_h__
#define PendingTransactionQueue_h__
#include "nsHttpTransaction.h"
#include "PendingTransactionInfo.h"
namespace mozilla {
namespace net {

View File

@ -141,6 +141,7 @@ UNIFIED_SOURCES += [
"NullHttpChannel.cpp",
"NullHttpTransaction.cpp",
"ParentChannelListener.cpp",
"PendingTransactionInfo.cpp",
"PendingTransactionQueue.cpp",
"QuicSocketControl.cpp",
"SpeculativeTransaction.cpp",

View File

@ -907,62 +907,14 @@ bool nsHttpConnectionMgr::DispatchPendingQ(
// dispatch. if considerAll == true then try and dispatch all items.
for (uint32_t i = 0; i < pendingQ.Length();) {
pendingTransInfo = pendingQ[i];
LOG((
"nsHttpConnectionMgr::DispatchPendingQ "
"[trans=%p, halfOpen=%p, activeConn=%p]\n",
pendingTransInfo->mTransaction.get(), pendingTransInfo->mHalfOpen.get(),
pendingTransInfo->mActiveConn.get()));
// When this transaction has already established a half-open
// connection, we want to prevent any duplicate half-open
// connections from being established and bound to this
// transaction. Allow only use of an idle persistent connection
// (if found) for transactions referred by a half-open connection.
bool alreadyHalfOpenOrWaitingForTLS = false;
if (pendingTransInfo->mHalfOpen) {
MOZ_ASSERT(!pendingTransInfo->mActiveConn);
RefPtr<HalfOpenSocket> halfOpen =
do_QueryReferent(pendingTransInfo->mHalfOpen);
LOG(
("nsHttpConnectionMgr::DispatchPendingQ "
"[trans=%p, halfOpen=%p]\n",
pendingTransInfo->mTransaction.get(), halfOpen.get()));
if (halfOpen) {
alreadyHalfOpenOrWaitingForTLS = true;
} else {
// If we have not found the halfOpen socket, remove the pointer.
pendingTransInfo->mHalfOpen = nullptr;
}
} else if (pendingTransInfo->mActiveConn) {
MOZ_ASSERT(!pendingTransInfo->mHalfOpen);
RefPtr<HttpConnectionBase> activeConn =
do_QueryReferent(pendingTransInfo->mActiveConn);
LOG(
("nsHttpConnectionMgr::DispatchPendingQ "
"[trans=%p, activeConn=%p]\n",
pendingTransInfo->mTransaction.get(), activeConn.get()));
// Check if this transaction claimed a connection that is still
// performing tls handshake with a NullHttpTransaction or it is between
// finishing tls and reclaiming (When nullTrans finishes tls handshake,
// httpConnection does not have a transaction any more and a
// ReclaimConnection is dispatched). But if an error occurred the
// connection will be closed, it will exist but CanReused will be
// false.
if (activeConn &&
((activeConn->Transaction() &&
activeConn->Transaction()->IsNullTransaction()) ||
(!activeConn->Transaction() && activeConn->CanReuse()))) {
alreadyHalfOpenOrWaitingForTLS = true;
} else {
// If we have not found the connection, remove the pointer.
pendingTransInfo->mActiveConn = nullptr;
}
}
bool alreadyHalfOpenOrWaitingForTLS =
pendingTransInfo->IsAlreadyClaimedInitializingConn();
rv = TryDispatchTransaction(
ent,
alreadyHalfOpenOrWaitingForTLS ||
!!pendingTransInfo->mTransaction->TunnelProvider(),
!!pendingTransInfo->Transaction()->TunnelProvider(),
pendingTransInfo);
if (NS_SUCCEEDED(rv) || (rv != NS_ERROR_NOT_AVAILABLE)) {
if (NS_SUCCEEDED(rv)) {
@ -973,7 +925,6 @@ bool nsHttpConnectionMgr::DispatchPendingQ(
"TryDispatchTransaction returning hard error %" PRIx32 "\n",
static_cast<uint32_t>(rv)));
}
ReleaseClaimedSockets(ent, pendingTransInfo);
if (pendingQ.RemoveElement(pendingTransInfo)) {
// pendingTransInfo is now potentially destroyed
dispatchedSuccessfully = true;
@ -1214,14 +1165,14 @@ bool nsHttpConnectionMgr::AtActiveConnectionLimit(ConnectionEntry* ent,
nsresult nsHttpConnectionMgr::MakeNewConnection(
ConnectionEntry* ent, PendingTransactionInfo* pendingTransInfo) {
LOG(("nsHttpConnectionMgr::MakeNewConnection %p ent=%p trans=%p", this, ent,
pendingTransInfo->mTransaction.get()));
pendingTransInfo->Transaction()));
MOZ_ASSERT(OnSocketThread(), "not on socket thread");
if (ent->FindConnToClaim(pendingTransInfo)) {
return NS_OK;
}
nsHttpTransaction* trans = pendingTransInfo->mTransaction;
nsHttpTransaction* trans = pendingTransInfo->Transaction();
// If this host is trying to negotiate a SPDY session right now,
// don't create any new connections until the result of the
@ -1304,17 +1255,15 @@ nsresult nsHttpConnectionMgr::TryDispatchTransaction(
PendingTransactionInfo* pendingTransInfo) {
MOZ_ASSERT(OnSocketThread(), "not on socket thread");
nsHttpTransaction* trans = pendingTransInfo->mTransaction;
nsHttpTransaction* trans = pendingTransInfo->Transaction();
LOG(
("nsHttpConnectionMgr::TryDispatchTransaction without conn "
"[trans=%p halfOpen=%p conn=%p ci=%p ci=%s caps=%x tunnelprovider=%p "
"[trans=%p ci=%p ci=%s caps=%x tunnelprovider=%p "
"onlyreused=%d active=%zu idle=%zu]\n",
trans, pendingTransInfo->mHalfOpen.get(),
pendingTransInfo->mActiveConn.get(), ent->mConnInfo.get(),
ent->mConnInfo->HashKey().get(), uint32_t(trans->Caps()),
trans->TunnelProvider(), onlyReusedConnection, ent->ActiveConnsLength(),
ent->IdleConnectionsLength()));
trans, ent->mConnInfo.get(), ent->mConnInfo->HashKey().get(),
uint32_t(trans->Caps()), trans->TunnelProvider(), onlyReusedConnection,
ent->ActiveConnsLength(), ent->IdleConnectionsLength()));
uint32_t caps = trans->Caps();
@ -1498,7 +1447,7 @@ nsresult nsHttpConnectionMgr::TryDispatchTransactionOnIdleConn(
bool respectUrgency, bool* allUrgent) {
bool onlyUrgent = !!ent->IdleConnectionsLength();
nsHttpTransaction* trans = pendingTransInfo->mTransaction;
nsHttpTransaction* trans = pendingTransInfo->Transaction();
bool urgentTrans = trans->ClassOfService() & nsIClassOfService::UrgentStart;
LOG(
@ -1757,33 +1706,6 @@ void nsHttpConnectionMgr::RecvdConnect() {
ConditionallyStopTimeoutTick();
}
void nsHttpConnectionMgr::ReleaseClaimedSockets(
ConnectionEntry* ent, PendingTransactionInfo* pendingTransInfo) {
if (pendingTransInfo->mHalfOpen) {
RefPtr<HalfOpenSocket> halfOpen =
do_QueryReferent(pendingTransInfo->mHalfOpen);
LOG(
("nsHttpConnectionMgr::ReleaseClaimedSockets "
"[trans=%p halfOpen=%p]",
pendingTransInfo->mTransaction.get(), halfOpen.get()));
if (halfOpen) {
halfOpen->Unclaim();
}
pendingTransInfo->mHalfOpen = nullptr;
} else if (pendingTransInfo->mActiveConn) {
RefPtr<HttpConnectionBase> activeConn =
do_QueryReferent(pendingTransInfo->mActiveConn);
if (activeConn && activeConn->Transaction() &&
activeConn->Transaction()->IsNullTransaction()) {
NullHttpTransaction* nullTrans =
activeConn->Transaction()->QueryNullTransaction();
nullTrans->Unclaim();
LOG(("nsHttpConnectionMgr::ReleaseClaimedSockets - mark %p unclaimed.",
activeConn.get()));
}
}
}
nsresult nsHttpConnectionMgr::CreateTransport(
ConnectionEntry* ent, nsAHttpTransaction* trans, uint32_t caps,
bool speculative, bool isFromPredictor, bool urgentStart, bool allow1918,
@ -1805,9 +1727,7 @@ nsresult nsHttpConnectionMgr::CreateTransport(
NS_ENSURE_SUCCESS(rv, rv);
if (pendingTransInfo) {
pendingTransInfo->mHalfOpen =
do_GetWeakReference(static_cast<nsISupportsWeakReference*>(sock));
DebugOnly<bool> claimed = sock->Claim();
DebugOnly<bool> claimed = pendingTransInfo->TryClaimingHalfOpen(sock);
MOZ_ASSERT(claimed);
}
@ -1829,23 +1749,22 @@ void nsHttpConnectionMgr::DispatchSpdyPendingQ(
++index) {
PendingTransactionInfo* pendingTransInfo = pendingQ[index];
if (!(pendingTransInfo->mTransaction->Caps() & NS_HTTP_ALLOW_KEEPALIVE) ||
pendingTransInfo->mTransaction->Caps() & NS_HTTP_DISALLOW_SPDY) {
if (!(pendingTransInfo->Transaction()->Caps() & NS_HTTP_ALLOW_KEEPALIVE) ||
pendingTransInfo->Transaction()->Caps() & NS_HTTP_DISALLOW_SPDY) {
leftovers.AppendElement(pendingTransInfo);
continue;
}
nsresult rv =
DispatchTransaction(ent, pendingTransInfo->mTransaction, conn);
DispatchTransaction(ent, pendingTransInfo->Transaction(), conn);
if (NS_FAILED(rv)) {
// this cannot happen, but if due to some bug it does then
// close the transaction
MOZ_ASSERT(false, "Dispatch SPDY Transaction");
LOG(("ProcessSpdyPendingQ Dispatch Transaction failed trans=%p\n",
pendingTransInfo->mTransaction.get()));
pendingTransInfo->mTransaction->Close(rv);
pendingTransInfo->Transaction()));
pendingTransInfo->Transaction()->Close(rv);
}
ReleaseClaimedSockets(ent, pendingTransInfo);
}
// Slurp up the rest of the pending queue into our leftovers bucket (we
@ -2127,19 +2046,12 @@ void nsHttpConnectionMgr::OnMsgCancelTransaction(int32_t reason,
" found in urgentStart queue\n",
trans));
pendingTransInfo = (*infoArray)[transIndex];
// We do not need to ReleaseClaimedSockets while we are
// going to close them all any way!
infoArray->RemoveElementAt(transIndex);
}
// Abandon all half-open sockets belonging to the given transaction.
if (pendingTransInfo) {
RefPtr<HalfOpenSocket> half =
do_QueryReferent(pendingTransInfo->mHalfOpen);
if (half) {
half->Abandon();
}
pendingTransInfo->mHalfOpen = nullptr;
pendingTransInfo->AbandonHalfOpenAndForgetActiveConn();
}
}
@ -3549,15 +3461,10 @@ bool nsHttpConnectionMgr::MoveTransToHTTPSSVCConnEntry(
return false;
}
MOZ_ASSERT(pendingTransInfo->mTransaction == aTrans);
MOZ_ASSERT(pendingTransInfo->Transaction() == aTrans);
// Abandon all half-open sockets belonging to the given transaction.
RefPtr<HalfOpenSocket> half = do_QueryReferent(pendingTransInfo->mHalfOpen);
if (half) {
half->Abandon();
}
pendingTransInfo->mHalfOpen = nullptr;
pendingTransInfo->mActiveConn = nullptr;
pendingTransInfo->AbandonHalfOpenAndForgetActiveConn();
// Step 3: Add the transaction to the new entry.
aTrans->UpdateConnectionInfo(aNewCI);

View File

@ -158,8 +158,8 @@ class nsHttpConnectionMgr final : public HttpConnectionMgrShell,
already_AddRefed<PendingTransactionInfo> FindTransactionHelper(
bool removeWhenFound, ConnectionEntry* aEnt, nsAHttpTransaction* aTrans);
// Wen a new idle connection has been added, this function is called to increment
// mNumIdleConns and update PruneDeadConnections timer.
// Wen a new idle connection has been added, this function is called to
// increment mNumIdleConns and update PruneDeadConnections timer.
void NewIdleConnectionAdded(uint32_t timeToLive);
void DecrementNumIdleConns();
@ -184,7 +184,7 @@ class nsHttpConnectionMgr final : public HttpConnectionMgrShell,
public:
bool Equals(const PendingTransactionInfo* aPendingTrans,
const nsAHttpTransaction* aTrans) const {
return aPendingTrans->mTransaction.get() == aTrans;
return aPendingTrans->Transaction() == aTrans;
}
};
@ -261,12 +261,6 @@ class nsHttpConnectionMgr final : public HttpConnectionMgrShell,
void StartedConnect();
void RecvdConnect();
// This function will unclaim the claimed connection or set a halfOpen
// socket to the speculative state if the transaction claiming them ends up
// using another connection.
void ReleaseClaimedSockets(ConnectionEntry* ent,
PendingTransactionInfo* pendingTransInfo);
ConnectionEntry* GetOrCreateConnectionEntry(nsHttpConnectionInfo*,
bool allowWildCard,
bool aNoHttp3);