From 0f4a77303fedfaa57977d6ca528799305eac9367 Mon Sep 17 00:00:00 2001 From: Roger Planas Date: Fri, 12 Oct 2018 11:29:17 +0100 Subject: Fix Component's disconnect to run event loop while isActive The Component::disconnect() was controlling the running of the event loop with the isAvailable flag, but it turns out that depending on timing, a re-connect could be attempted and the component erroneously claim that the "Component is already connecting or connected", which could not possibly the case if the first attempt to connect the component failed (hence, not possible it was connected). By updating the event loop to use the correct isActive flag, this issue is fixed. This error was highlighted as a result of the previous commit "Prevent connect on active sluift clients and components". Also, the getNextEvent is fixed to do not suffer from the same problem, and use isActive instead of isAvailable. Test-information: Before the patch, a test that would attempt a second component connect after a failed one would randomly fail. After the patch, a test that would attempt a second component connect after a failed one has passed hundreds of time without failure. Change-Id: I20be6b1c8aec485ded3330c143dedd2161c4c66e diff --git a/Sluift/SluiftComponent.cpp b/Sluift/SluiftComponent.cpp index 126562e..ee09380 100644 --- a/Sluift/SluiftComponent.cpp +++ b/Sluift/SluiftComponent.cpp @@ -78,7 +78,7 @@ bool SluiftComponent::isConnected() const { void SluiftComponent::disconnect() { component->disconnect(); - while (component->isAvailable()) { + while (component->isActive()) { eventLoop->runUntilEvents(); } } @@ -105,12 +105,12 @@ boost::optional SluiftComponent::getNextEvent( } // Wait for new events - while (!watchdog.getTimedOut() && currentIndex >= pendingEvents.size() && component->isAvailable()) { + while (!watchdog.getTimedOut() && currentIndex >= pendingEvents.size() && component->isActive()) { eventLoop->runUntilEvents(); } // Finish if we're disconnected or timed out - if (watchdog.getTimedOut() || !component->isAvailable()) { + if (watchdog.getTimedOut() || !component->isActive()) { return boost::optional(); } } -- cgit v0.10.2-6-g49f6