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