From d7b86d83de8b9b452243eac841af80cfa4327c03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Remko=20Tron=C3=A7on?= Date: Sat, 18 Jan 2014 11:41:10 +0100 Subject: Sluift: Keep unprocessed events in queue Iterators over specific events (e.g. get_next_message) would discard other events arriving in the meantime. This no longer is the case. Change-Id: I615295695f7104eff7c4c9a642aa57f7c78a08c9 diff --git a/Sluift/SluiftClient.cpp b/Sluift/SluiftClient.cpp index 8c0213e..3bc03c8 100644 --- a/Sluift/SluiftClient.cpp +++ b/Sluift/SluiftClient.cpp @@ -97,18 +97,22 @@ void SluiftClient::setSoftwareVersion(const std::string& name, const std::string boost::optional SluiftClient::getNextEvent( int timeout, boost::function condition) { Watchdog watchdog(timeout, networkFactories->getTimerFactory()); + size_t currentIndex = 0; while (true) { // Look for pending events in the queue - while (!pendingEvents.empty()) { - Event event = pendingEvents.front(); - pendingEvents.pop_front(); + while (currentIndex < pendingEvents.size()) { + Event event = pendingEvents[currentIndex]; if (!condition || condition(event)) { + pendingEvents.erase( + pendingEvents.begin() + + boost::numeric_cast(currentIndex)); return event; } + ++currentIndex; } // Wait for new events - while (!watchdog.getTimedOut() && pendingEvents.empty() && client->isActive()) { + while (!watchdog.getTimedOut() && currentIndex >= pendingEvents.size() && client->isActive()) { eventLoop->runUntilEvents(); } -- cgit v0.10.2-6-g49f6