Browse Source

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

tags/2021-05-28
Tom Poole hogliux 7 years ago
parent
commit
8782bdd6ba
1 changed files with 14 additions and 10 deletions
  1. +14
    -10
      modules/juce_analytics/destinations/juce_ThreadedAnalyticsDestination.cpp

+ 14
- 10
modules/juce_analytics/destinations/juce_ThreadedAnalyticsDestination.cpp 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 numEventsInQueue = (int) eventQueue.size();
const auto numEventsInBatch = eventsToSend.size();
const auto freeBatchCapacity = maxBatchSize - numEventsInBatch;
if (numEventsInQueue > 0)
if (freeBatchCapacity > 0)
{
const auto numEventsToAdd = jmin (eventsToSendCapacity, numEventsInQueue);
const auto numNewEvents = (int) eventQueue.size() - numEventsInBatch;
if (numNewEvents > 0)
{
const ScopedLock lock (queueAccess);
const auto numEventsToAdd = jmin (numNewEvents, freeBatchCapacity);
const auto newBatchSize = numEventsInBatch + numEventsToAdd;
for (size_t i = 0; i < (size_t) numEventsToAdd; ++i)
eventsToSend.add (eventQueue[i]);
for (size_t i = numEventsInBatch; i < (size_t) newBatchSize; ++i)
eventsToSend.add (eventQueue[i]);
}
}
}


Loading…
Cancel
Save