Avoid adding more that one “XMPP reconnection” timed event at the same time
Fix a semblance of infinite and busy loop, that could occur if biboumi’s poller is woken up multiple times while the XMPP server is not reachable.
This commit is contained in:
+3
-2
@@ -179,19 +179,20 @@ int main(int ac, char** av)
|
||||
{
|
||||
if (xmpp_component->ever_auth)
|
||||
{
|
||||
static const std::string reconnect_name{"XMPP reconnection"};
|
||||
if (xmpp_component->first_connection_try == true)
|
||||
{ // immediately re-try to connect
|
||||
xmpp_component->reset();
|
||||
xmpp_component->start();
|
||||
}
|
||||
else
|
||||
else if (!TimedEventsManager::instance().find_event(reconnect_name))
|
||||
{ // Re-connecting failed, we now try only each few seconds
|
||||
auto reconnect_later = [xmpp_component]()
|
||||
{
|
||||
xmpp_component->reset();
|
||||
xmpp_component->start();
|
||||
};
|
||||
TimedEvent event(std::chrono::steady_clock::now() + 2s, reconnect_later, "XMPP reconnection");
|
||||
TimedEvent event(std::chrono::steady_clock::now() + 2s, reconnect_later, reconnect_name);
|
||||
TimedEventsManager::instance().add_event(std::move(event));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user