Add mutex to message sending function.
This commit is contained in:
parent
8a92e808f3
commit
dfd9399666
10
socket.cpp
10
socket.cpp
|
@ -19,6 +19,8 @@
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
#include <QMutex>
|
||||||
#include <QThread>
|
#include <QThread>
|
||||||
#include <QUdpSocket>
|
#include <QUdpSocket>
|
||||||
|
|
||||||
|
@ -74,6 +76,10 @@ void Socket::sendDatagram ( Datagram d )
|
||||||
|
|
||||||
void Socket::run()
|
void Socket::run()
|
||||||
{
|
{
|
||||||
|
QMutex mutex;
|
||||||
|
if (!mutex.tryLock())
|
||||||
|
return;
|
||||||
|
|
||||||
unsigned short retryCount = 0;
|
unsigned short retryCount = 0;
|
||||||
QByteArray currentDatagram, previousDatagram = 0, recordLength;
|
QByteArray currentDatagram, previousDatagram = 0, recordLength;
|
||||||
while ( commands.size() > 0 )
|
while ( commands.size() > 0 )
|
||||||
|
@ -96,6 +102,7 @@ void Socket::run()
|
||||||
previousDatagram = currentDatagram;
|
previousDatagram = currentDatagram;
|
||||||
QThread::msleep(100);
|
QThread::msleep(100);
|
||||||
}
|
}
|
||||||
|
mutex.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Socket::subscribe()
|
void Socket::subscribe()
|
||||||
|
@ -202,7 +209,7 @@ bool Socket::parseReply ( QByteArray reply )
|
||||||
break;
|
break;
|
||||||
case SocketData:
|
case SocketData:
|
||||||
{
|
{
|
||||||
std::cout << reply.toHex().toStdString() << " " << datagram << std::endl; // for debugging purposes only
|
// std::cout << reply.toHex().toStdString() << " " << datagram << std::endl; // for debugging purposes only
|
||||||
unsigned short int index = reply.indexOf ( rmac + twenties );
|
unsigned short int index = reply.indexOf ( rmac + twenties );
|
||||||
versionID = reply.mid ( index - 14, 2 );
|
versionID = reply.mid ( index - 14, 2 );
|
||||||
index += 12; // length of rmac + padding
|
index += 12; // length of rmac + padding
|
||||||
|
@ -241,6 +248,7 @@ bool Socket::parseReply ( QByteArray reply )
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case TimingData:
|
case TimingData:
|
||||||
|
std::cout << reply.toHex().toStdString() << " " << datagram << std::endl; // for debugging purposes only
|
||||||
break;
|
break;
|
||||||
case WriteSocketData:
|
case WriteSocketData:
|
||||||
sendDatagram ( SocketData );
|
sendDatagram ( SocketData );
|
||||||
|
|
Loading…
Reference in New Issue