From 30d5858663edd0ab5433bbe9f0a38b7345356fa5 Mon Sep 17 00:00:00 2001 From: Phil Taylor Date: Fri, 28 Jan 2022 09:43:53 +0000 Subject: [PATCH] Max missing packets slightly less than buffer size --- packettypes.h | 1 + udphandler.cpp | 2 +- udpserver.cpp | 7 ++++--- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/packettypes.h b/packettypes.h index f2f46af..ef471e6 100644 --- a/packettypes.h +++ b/packettypes.h @@ -15,6 +15,7 @@ #define LOCK_PERIOD 10 // How long to try to lock mutex (ms) #define STALE_CONNECTION 15 // Not heard from in this many seconds #define BUFSIZE 500 // Number of packets to buffer +#define MAX_MISSING 400 // Make the maximum number of possible missing packets less than total buffer size! #define TXAUDIO_PERIOD 20 diff --git a/udphandler.cpp b/udphandler.cpp index 8890694..160d52f 100644 --- a/udphandler.cpp +++ b/udphandler.cpp @@ -1322,7 +1322,7 @@ void udpBase::sendRetransmitRequest() if (rxMissing.isEmpty()) { return; } - else if (rxMissing.size() > 100) { + else if (rxMissing.size() > MAX_MISSING) { qDebug(logUdp()) << "Too many missing packets," << rxMissing.size() << "flushing all buffers"; missingMutex.lock(); rxMissing.clear(); diff --git a/udpserver.cpp b/udpserver.cpp index d1059dd..a79c4ee 100644 --- a/udpserver.cpp +++ b/udpserver.cpp @@ -823,11 +823,12 @@ void udpServer::commonReceived(QList* l, CLIENT* current, QByteArray r) { for (quint16 i = 0x10; i < r.length(); i = i + 2) { - auto match = std::find_if(current->txSeqBuf.begin(), current->txSeqBuf.end(), [&cs = in->seq](SEQBUFENTRY& s) { + quint16 seq = (quint8)r[i] | (quint8)r[i + 1] << 8; + auto match = std::find_if(current->txSeqBuf.begin(), current->txSeqBuf.end(), [&cs = seq](SEQBUFENTRY& s) { return s.seqNum == cs; }); if (match == current->txSeqBuf.end()) { - qInfo(logUdpServer()) << current->ipAddress.toString() << "(" << current->type << "): Requested packet " << hex << in->seq << " not found"; + qInfo(logUdpServer()) << current->ipAddress.toString() << "(" << current->type << "): Requested packet " << hex << seq << " not found"; // Just send idle packet. sendControl(current, 0, in->seq); } @@ -1688,7 +1689,7 @@ void udpServer::sendRetransmitRequest(CLIENT* c) if (c->rxMissing.isEmpty()) { return; } - else if (c->rxMissing.size() > 100) { + else if (c->rxMissing.size() > MAX_MISSING) { qDebug(logUdp()) << "Too many missing packets," << c->rxMissing.size() << "flushing all buffers"; c->rxMutex.lock(); c->rxSeqBuf.clear();