From 32384047537ed7c63cf3099b247777ed6035af49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Mon, 17 Apr 2017 14:45:19 +0200 Subject: =?UTF-8?q?Avoid=20adding=20more=20that=20one=20=E2=80=9CXMPP=20re?= =?UTF-8?q?connection=E2=80=9D=20timed=20event=20at=20the=20same=20time?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- src/main.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/main.cpp') diff --git a/src/main.cpp b/src/main.cpp index 2db89cc..1a9b065 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -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)); } } -- cgit v1.2.3