From fe7bdf134538e382549b6dbc592e4820a12bc041 Mon Sep 17 00:00:00 2001 From: Phil Taylor Date: Thu, 27 Jan 2022 23:24:54 +0000 Subject: [PATCH] Flush buffers on excessive missing --- udphandler.cpp | 18 ++++++++++-------- udpserver.cpp | 19 +++++++++++-------- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/udphandler.cpp b/udphandler.cpp index 1adbbd1..596afc3 100644 --- a/udphandler.cpp +++ b/udphandler.cpp @@ -1268,14 +1268,6 @@ void udpBase::dataReceived(QByteArray r) int missCounter = 0; for (quint16 f = rxSeqBuf.lastKey() + 1; f < in->seq; f++) { - if (missCounter > 50) { - // More than 50 packets missing, something horrific has happened! - qDebug(logUdp()) << "Too many missing packets, full reset!"; - rxSeqBuf.clear(); - rxMissing.clear(); - missingMutex.unlock(); - break; - } qDebug(logUdp()) << "Detected missing packet" << f; if (rxSeqBuf.size() > BUFSIZE) @@ -1330,6 +1322,16 @@ void udpBase::sendRetransmitRequest() if (rxMissing.isEmpty()) { return; } + else if (rxMissing.size() > 100) { + qDebug(logUdp()) << "Too many missing packets," << rxMissing.size() << "flushing all buffers"; + missingMutex.lock(); + rxBufferMutex.lock(); + qDebug(logUdp()) << "Too many missing packets, full reset!"; + rxSeqBuf.clear(); + rxMissing.clear(); + missingMutex.unlock(); + return; + } QByteArray missingSeqs; diff --git a/udpserver.cpp b/udpserver.cpp index 95d2920..a922367 100644 --- a/udpserver.cpp +++ b/udpserver.cpp @@ -908,14 +908,6 @@ void udpServer::commonReceived(QList* l, CLIENT* current, QByteArray r) for (quint16 f = current->rxSeqBuf.lastKey() + 1; f < in->seq; f++) { - if (missCounter > 50) { - // More than 50 packets missing, something horrific has happened! - qDebug(logUdpServer()) << "Too many missing packets, full reset!"; - current->rxSeqBuf.clear(); - current->rxMissing.clear(); - current->missMutex.unlock(); - break; - } qInfo(logUdpServer()) << "Detected missing packet" << f; @@ -1696,6 +1688,17 @@ void udpServer::sendRetransmitRequest(CLIENT* c) if (c->rxMissing.isEmpty()) { return; } + else if (c->rxMissing.size() > 100) { + qDebug(logUdp()) << "Too many missing packets," << c->rxMissing.size() << "flushing all buffers"; + c->missMutex.lock(); + c->rxMutex.lock(); + qDebug(logUdp()) << "Too many missing packets, full reset!"; + c->rxSeqBuf.clear(); + c->rxMissing.clear(); + c->missMutex.unlock(); + return; + } + QByteArray missingSeqs;