From 8a92e808f3e18faadb3314c67801c3456983a3ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrius=20=C5=A0tikonas?= Date: Mon, 2 Mar 2015 12:21:10 +0000 Subject: [PATCH] Stop trying to send the same datagram if it repeatedly fails. --- socket.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/socket.cpp b/socket.cpp index 605c7c4..fbe51e2 100644 --- a/socket.cpp +++ b/socket.cpp @@ -74,17 +74,26 @@ void Socket::sendDatagram ( Datagram d ) void Socket::run() { + unsigned short retryCount = 0; + QByteArray currentDatagram, previousDatagram = 0, recordLength; while ( commands.size() > 0 ) { - QByteArray currentDatagram = datagram[commands.head()]; - QByteArray recordLength; + currentDatagram = datagram[commands.head()]; + if ( previousDatagram == currentDatagram ) + ++retryCount; + if ( retryCount == 5 ) + { + std::cout << "Stop retrying: " << currentDatagram.toHex().toStdString() << std::endl; + commands.dequeue(); + retryCount = 0; + } QDataStream stream(&recordLength, QIODevice::WriteOnly); stream.setByteOrder(QDataStream::BigEndian); uint16_t length = currentDatagram.length() + 4; // +4 for magicKey and total message length stream << length; - currentDatagram = magicKey + recordLength + currentDatagram; - udpSocket->write ( currentDatagram ); + udpSocket->write ( magicKey + recordLength + currentDatagram ); + previousDatagram = currentDatagram; QThread::msleep(100); } }