summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2014-01-18 10:41:10 (GMT)
committerRemko Tronçon <git@el-tramo.be>2014-01-18 10:44:43 (GMT)
commitd7b86d83de8b9b452243eac841af80cfa4327c03 (patch)
tree151972ec74067cb4498b8217b8860db3c5de800a
parent60c07599cd3ea8a5befbb3ce5e1e7837b875f2d6 (diff)
downloadswift-contrib-d7b86d83de8b9b452243eac841af80cfa4327c03.zip
swift-contrib-d7b86d83de8b9b452243eac841af80cfa4327c03.tar.bz2
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
-rw-r--r--Sluift/SluiftClient.cpp12
1 files changed, 8 insertions, 4 deletions
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::Event> SluiftClient::getNextEvent(
int timeout, boost::function<bool (const Event&)> 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<int>(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();
}