From 42ac954475351e2cb7cab13e596c97bd9cc785d9 Mon Sep 17 00:00:00 2001 From: Asbelos Date: Fri, 5 Aug 2022 18:14:22 +0100 Subject: [PATCH] Forget withrottle client on disconnect --- CommandDistributor.cpp | 1 + WiThrottle.cpp | 8 ++++++++ WiThrottle.h | 1 + 3 files changed, 10 insertions(+) diff --git a/CommandDistributor.cpp b/CommandDistributor.cpp index a0ebccd..f8dc259 100644 --- a/CommandDistributor.cpp +++ b/CommandDistributor.cpp @@ -82,6 +82,7 @@ void CommandDistributor::parse(byte clientId,byte * buffer, RingStream * stream } void CommandDistributor::forget(byte clientId) { + if (clients[clientId]==WITHROTTLE_TYPE) WiThrottle::forget(clientId); clients[clientId]=NONE_TYPE; } #endif diff --git a/WiThrottle.cpp b/WiThrottle.cpp index 66463de..e2e7d95 100644 --- a/WiThrottle.cpp +++ b/WiThrottle.cpp @@ -69,6 +69,14 @@ WiThrottle* WiThrottle::getThrottle( int wifiClient) { return new WiThrottle( wifiClient); } +void WiThrottle::forget( byte clientId) { + for (WiThrottle* wt=firstThrottle; wt!=NULL ; wt=wt->nextThrottle) + if (wt->clientid==clientId) { + delete wt; + break; + } +} + bool WiThrottle::isThrottleInUse(int cab) { for (WiThrottle* wt=firstThrottle; wt!=NULL ; wt=wt->nextThrottle) if (wt->areYouUsingThrottle(cab)) return true; diff --git a/WiThrottle.h b/WiThrottle.h index 54ca703..253787d 100644 --- a/WiThrottle.h +++ b/WiThrottle.h @@ -37,6 +37,7 @@ class WiThrottle { void parse(RingStream * stream, byte * cmd); static WiThrottle* getThrottle( int wifiClient); static void markForBroadcast(int cab); + static void forget(byte clientId); private: WiThrottle( int wifiClientId);