Stop trying to send the same datagram if it repeatedly fails.
This commit is contained in:
parent
6208514f70
commit
8a92e808f3
17
socket.cpp
17
socket.cpp
|
@ -74,17 +74,26 @@ void Socket::sendDatagram ( Datagram d )
|
||||||
|
|
||||||
void Socket::run()
|
void Socket::run()
|
||||||
{
|
{
|
||||||
|
unsigned short retryCount = 0;
|
||||||
|
QByteArray currentDatagram, previousDatagram = 0, recordLength;
|
||||||
while ( commands.size() > 0 )
|
while ( commands.size() > 0 )
|
||||||
{
|
{
|
||||||
QByteArray currentDatagram = datagram[commands.head()];
|
currentDatagram = datagram[commands.head()];
|
||||||
QByteArray recordLength;
|
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);
|
QDataStream stream(&recordLength, QIODevice::WriteOnly);
|
||||||
stream.setByteOrder(QDataStream::BigEndian);
|
stream.setByteOrder(QDataStream::BigEndian);
|
||||||
uint16_t length = currentDatagram.length() + 4; // +4 for magicKey and total message length
|
uint16_t length = currentDatagram.length() + 4; // +4 for magicKey and total message length
|
||||||
stream << length;
|
stream << length;
|
||||||
currentDatagram = magicKey + recordLength + currentDatagram;
|
|
||||||
|
|
||||||
udpSocket->write ( currentDatagram );
|
udpSocket->write ( magicKey + recordLength + currentDatagram );
|
||||||
|
previousDatagram = currentDatagram;
|
||||||
QThread::msleep(100);
|
QThread::msleep(100);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue