From 9f1eeff477d63900862d57e69aa19bf5ce2372ae Mon Sep 17 00:00:00 2001 From: Justin Karneges Date: Mon, 9 Sep 2024 15:09:03 -0700 Subject: [PATCH] consolidate --- src/handler/httpsession.cpp | 62 ++++++++++++++++++++----------------- 1 file changed, 34 insertions(+), 28 deletions(-) diff --git a/src/handler/httpsession.cpp b/src/handler/httpsession.cpp index 26532750..84b3cf2b 100644 --- a/src/handler/httpsession.cpp +++ b/src/handler/httpsession.cpp @@ -175,7 +175,7 @@ class HttpSession::Private : public QObject FilterStack *responseFilters; QSet activeChannels; int connectionSubscriptionMax; - bool needRemoveFromStats; + bool connectionStatsActive; Callback> subscribeCallback; Callback> unsubscribeCallback; Callback> finishedCallback; @@ -205,7 +205,7 @@ class HttpSession::Private : public QObject pendingAction(0), responseFilters(0), connectionSubscriptionMax(_connectionSubscriptionMax), - needRemoveFromStats(true) + connectionStatsActive(true) { state = NotStarted; @@ -237,16 +237,6 @@ class HttpSession::Private : public QObject { cleanup(); - if(needRemoveFromStats) - { - ZhttpRequest::Rid rid = req->rid(); - QByteArray cid = rid.first + ':' + rid.second; - - stats->removeConnection(cid, false); - } - - updateManager->unregisterSession(q); - timerConnection.disconnect(); timer->setParent(0); timer->deleteLater(); @@ -361,7 +351,7 @@ class HttpSession::Private : public QObject if(priority == HighPriority) { // switching to high priority - cleanupAction(); + cancelAction(); state = Holding; } else @@ -528,8 +518,17 @@ class HttpSession::Private : public QObject private: void cleanup() { - cleanupOutReq(); - cleanupAction(); + cancelActivities(); + + if(connectionStatsActive) + { + connectionStatsActive = false; + + ZhttpRequest::Rid rid = req->rid(); + QByteArray cid = rid.first + ':' + rid.second; + + stats->removeConnection(cid, false); + } } void cleanupOutReq() @@ -542,7 +541,7 @@ class HttpSession::Private : public QObject responseFilters = 0; } - void cleanupAction() + void cancelAction() { if(pendingAction) { @@ -551,6 +550,19 @@ class HttpSession::Private : public QObject } } + void cancelActivities() + { + cleanupOutReq(); + cancelAction(); + + publishQueue.clear(); + + timer->stop(); + retryTimer->stop(); + + updateManager->unregisterSession(q); + } + void setupKeepAlive() { if(instruct.keepAliveTimeout >= 0) @@ -571,14 +583,9 @@ class HttpSession::Private : public QObject void prepareToClose() { - cleanupOutReq(); - cleanupAction(); - state = Closing; - publishQueue.clear(); - timer->stop(); - updateManager->unregisterSession(q); + cancelActivities(); } void tryWriteFirstInstructResponse() @@ -1068,12 +1075,11 @@ class HttpSession::Private : public QObject void doFinish(bool retry = false) { + cancelActivities(); + ZhttpRequest::Rid rid = req->rid(); QByteArray cid = rid.first + ':' + rid.second; - cleanupOutReq(); - cleanupAction(); - QPointer self = this; QHashIterator it(channels); @@ -1092,7 +1098,7 @@ class HttpSession::Private : public QObject // refresh before remove, to ensure transition stats->refreshConnection(cid); - needRemoveFromStats = false; + connectionStatsActive = false; int unreportedTime = stats->removeConnection(cid, true, adata.from); @@ -1157,7 +1163,7 @@ class HttpSession::Private : public QObject } else { - needRemoveFromStats = false; + connectionStatsActive = false; stats->removeConnection(cid, false); } @@ -1311,7 +1317,7 @@ class HttpSession::Private : public QObject retries = 0; - outReq.reset(); + cleanupOutReq(); bool ok; Instruct i = Instruct::fromResponse(responseData, &ok, &errorMessage);