QUdpSocket data loss using threads
-
Hi all,
I have been using QUdpSocket for a while now and we have legacy code that reimplements QThread. I converted the code so that I have a QObject named UDPServer that is passed to a QThread and executes it's event loop. Everything there works great. The problem I face is that the device I am communicating with bursts data packets, so I can a large chunk of UDP packets in a short period of time. I get significant data loss even with a large UDP buffer (using WinSock setsockopt). Here is what the architecture looks like:
QThread 1:
Running the event loop for the UDPServer which contains the QUDPSocketQThread 2:
Running the event loop for FileWriter (Basically writes the data to a file when signalled from the UDPServer)The UDPServer stores x number of data packets before signalling the FileWriter to write to a file. This is to decrease overhead and have burst writes. I basically toggle between two receive buffers and once one is full, send that off to be written.
Here are my questions:
In the UDPServer, the QUDPSocket readyReady signal is connected to slotReadReady(). In there we use the same code as the QUDOSocket example:@
while( m_p_UDPSocket->hasPendingDatagrams() ) {
// Process the data
}
@Is the while loop blocking the QUDPSocket from getting more data packets since it is in the same thread? Does anyone know of a good approach to a high performance QUDPSocket receiver?
Thank you for taking the time to read all of this, it's a lot :)