1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

Fixed a bug handling queued analytics events after a failed server connection attempt

This commit is contained in:
Tom Poole 2018-04-23 11:48:03 +01:00
parent 040a3168f3
commit b2f32a712f

View file

@ -89,20 +89,24 @@ void ThreadedAnalyticsDestination::EventDispatcher::run()
while (! threadShouldExit())
{
auto eventsToSendCapacity = maxBatchSize - eventsToSend.size();
if (eventsToSendCapacity > 0)
{
const ScopedLock lock (queueAccess);
const auto numEventsInBatch = eventsToSend.size();
const auto freeBatchCapacity = maxBatchSize - numEventsInBatch;
const auto numEventsInQueue = (int) eventQueue.size();
if (numEventsInQueue > 0)
if (freeBatchCapacity > 0)
{
const auto numEventsToAdd = jmin (eventsToSendCapacity, numEventsInQueue);
const auto numNewEvents = (int) eventQueue.size() - numEventsInBatch;
for (size_t i = 0; i < (size_t) numEventsToAdd; ++i)
eventsToSend.add (eventQueue[i]);
if (numNewEvents > 0)
{
const ScopedLock lock (queueAccess);
const auto numEventsToAdd = jmin (numNewEvents, freeBatchCapacity);
const auto newBatchSize = numEventsInBatch + numEventsToAdd;
for (size_t i = numEventsInBatch; i < (size_t) newBatchSize; ++i)
eventsToSend.add (eventQueue[i]);
}
}
}