summaryrefslogtreecommitdiff
path: root/src/main.cpp
diff options
context:
space:
mode:
authorFlorent Le Coz <louiz@louiz.org>2015-02-21 06:39:20 +0100
committerFlorent Le Coz <louiz@louiz.org>2015-02-21 06:45:11 +0100
commita50ca30e769a628f609f8cc0eedf5bc10b3f1b5a (patch)
tree9119399eefe68d086e80eeaa3fc35e673257cdc7 /src/main.cpp
parent3032dc3580e2d6c3fab57b587945fbb213271557 (diff)
downloadbiboumi-a50ca30e769a628f609f8cc0eedf5bc10b3f1b5a.tar.gz
biboumi-a50ca30e769a628f609f8cc0eedf5bc10b3f1b5a.tar.bz2
biboumi-a50ca30e769a628f609f8cc0eedf5bc10b3f1b5a.tar.xz
biboumi-a50ca30e769a628f609f8cc0eedf5bc10b3f1b5a.zip
Use a timer to try reconnecting to the XMPP server only each 2 seconds
When the connection is lost, immediately try to reconnect, then try to reconnect every 2 seconds. This is much better than the previous “Try to re-connect as fast as possible”.
Diffstat (limited to 'src/main.cpp')
-rw-r--r--src/main.cpp23
1 files changed, 21 insertions, 2 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 393bf05..a67baf9 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -108,6 +108,8 @@ int main(int ac, char** av)
exiting = true;
stop.store(false);
xmpp_component->shutdown();
+ // Cancel the timer for an potential reconnection
+ TimedEventsManager::instance().cancel("XMPP reconnection");
}
if (reload)
{
@@ -127,17 +129,34 @@ int main(int ac, char** av)
if (!exiting && xmpp_component->ever_auth &&
!xmpp_component->is_connected() &&
!xmpp_component->is_connecting())
- {
+ {
+ if (xmpp_component->first_connection_try == true)
+ { // immediately re-try to connect
xmpp_component->reset();
xmpp_component->start();
}
+ else
+ { // 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");
+ TimedEventsManager::instance().add_event(std::move(event));
+ }
+ }
// If the only existing connection is the one to the XMPP component:
// close the XMPP stream.
if (exiting && xmpp_component->is_connecting())
xmpp_component->close();
if (exiting && p->size() == 1 && xmpp_component->is_document_open())
xmpp_component->close_document();
- timeout = TimedEventsManager::instance().get_timeout();
+ if (exiting) // If we are exiting, do not wait for any timed event
+ timeout = utils::no_timeout;
+ else
+ timeout = TimedEventsManager::instance().get_timeout();
}
log_info("All connections cleanly closed, have a nice day.");
return 0;