From acce8dfa21ad617ba788704d1b737e60b58e53a5 Mon Sep 17 00:00:00 2001 From: Wiebe Cazemier Date: Sat, 12 Feb 2022 17:12:14 +0100 Subject: [PATCH] Get fresh QoS limits per write --- session.cpp | 9 +++++---- session.h | 2 -- settings.h | 4 ++-- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/session.cpp b/session.cpp index 91887e1..b439d9f 100644 --- a/session.cpp +++ b/session.cpp @@ -23,9 +23,7 @@ License along with FlashMQ. If not, see . std::chrono::time_point appStartTime = std::chrono::steady_clock::now(); -Session::Session() : - maxQosMsgPending(ThreadGlobals::getSettings()->maxQosMsgPendingPerClient), - maxQosBytesPending(ThreadGlobals::getSettings()->maxQosBytesPendingPerClient) +Session::Session() { } @@ -152,6 +150,8 @@ void Session::writePacket(MqttPacket &packet, char max_qos, std::shared_ptr(packet.getQos(), max_qos); + const Settings *settings = ThreadGlobals::getSettings(); + Authentication *_auth = ThreadGlobals::getAuth(); assert(_auth); Authentication &auth = *_auth; @@ -183,7 +183,8 @@ void Session::writePacket(MqttPacket &packet, char max_qos, std::shared_ptr locker(qosQueueMutex); const size_t totalQosPacketsInTransit = qosPacketQueue.size() + incomingQoS2MessageIds.size() + outgoingQoS2MessageIds.size(); - if (totalQosPacketsInTransit >= maxQosMsgPending || (qosPacketQueue.getByteSize() >= maxQosBytesPending && qosPacketQueue.size() > 0)) + if (totalQosPacketsInTransit >= settings->maxQosMsgPendingPerClient + || (qosPacketQueue.getByteSize() >= settings->maxQosBytesPendingPerClient && qosPacketQueue.size() > 0)) { if (QoSLogPrintedAtId != nextPacketId) { diff --git a/session.h b/session.h index 0f75b5e..8b54cd8 100644 --- a/session.h +++ b/session.h @@ -48,8 +48,6 @@ class Session uint16_t QoSLogPrintedAtId = 0; std::chrono::time_point lastTouched = std::chrono::steady_clock::now(); Logger *logger = Logger::getInstance(); - const size_t maxQosMsgPending = 0; - const size_t maxQosBytesPending = 0; int64_t getSessionRelativeAgeInMs() const; void setSessionTouch(int64_t ageInMs); diff --git a/settings.h b/settings.h index 37f9c6a..55d0216 100644 --- a/settings.h +++ b/settings.h @@ -56,8 +56,8 @@ public: int authPluginTimerPeriod = 60; std::string storageDir; int threadCount = 0; - int maxQosMsgPendingPerClient = 512; - int maxQosBytesPendingPerClient = 65536; + uint maxQosMsgPendingPerClient = 512; + uint maxQosBytesPendingPerClient = 65536; std::list> listeners; // Default one is created later, when none are defined. AuthOptCompatWrap &getAuthOptsCompat(); -- libgit2 0.21.4