From 7ccc5a963ab71e3f35a1a391c7680b26aa739789 Mon Sep 17 00:00:00 2001 From: Anonymous-275 Date: Tue, 30 Mar 2021 22:10:57 +0300 Subject: [PATCH] Clear the queue if we failed to sync it --- src/TNetwork.cpp | 8 +++++++- src/TServer.cpp | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/TNetwork.cpp b/src/TNetwork.cpp index 06d3e5d..beb0678 100644 --- a/src/TNetwork.cpp +++ b/src/TNetwork.cpp @@ -361,6 +361,12 @@ bool TNetwork::TCPSend(TClient& c, const std::string& Data, bool IsSync) { if (!TCPSend(c, QData, true)) { if (c.GetStatus() > -1) c.SetStatus(-1); + { + std::unique_lock lock(c.MissedPacketQueueMutex()); + while(!c.MissedPacketQueue().empty()){ + c.MissedPacketQueue().pop(); + } + } CloseSocketProper(c.GetTCPSock()); return false; } @@ -382,7 +388,7 @@ bool TNetwork::TCPSend(TClient& c, const std::string& Data, bool IsSync) { c.SetStatus(-1); return false; } else if (Temp < 0) { - debug("send() < 0: " + std::string(std::strerror(errno))); + debug("send() < 0: " + std::string(std::strerror(errno))); //TODO fix it was spamming yet everyone stayed on the server if (c.GetStatus() > -1) c.SetStatus(-1); CloseSocketProper(c.GetTCPSock()); diff --git a/src/TServer.cpp b/src/TServer.cpp index f4148a5..6111508 100644 --- a/src/TServer.cpp +++ b/src/TServer.cpp @@ -304,6 +304,6 @@ void TServer::Apply(TClient& c, int VID, const std::string& pckt) { void TServer::InsertClient(const std::shared_ptr& NewClient) { debug("inserting client (" + std::to_string(ClientCount()) + ")"); - WriteLock Lock(mClientsMutex); + WriteLock Lock(mClientsMutex); //TODO why is there 30+ threads locked here (void)mClients.insert(NewClient); }