summaryrefslogtreecommitdiff
path: root/src/xmpp
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/xmpp
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/xmpp')
-rw-r--r--src/xmpp/xmpp_component.cpp3
-rw-r--r--src/xmpp/xmpp_component.hpp6
2 files changed, 9 insertions, 0 deletions
diff --git a/src/xmpp/xmpp_component.cpp b/src/xmpp/xmpp_component.cpp
index 1335326..841ead4 100644
--- a/src/xmpp/xmpp_component.cpp
+++ b/src/xmpp/xmpp_component.cpp
@@ -39,6 +39,7 @@ static std::set<std::string> kickable_errors{
XmppComponent::XmppComponent(std::shared_ptr<Poller> poller, const std::string& hostname, const std::string& secret):
TCPSocketHandler(poller),
ever_auth(false),
+ first_connection_try(true),
served_hostname(hostname),
secret(secret),
authenticated(false),
@@ -86,6 +87,7 @@ void XmppComponent::send_stanza(const Stanza& stanza)
void XmppComponent::on_connection_failed(const std::string& reason)
{
+ this->first_connection_try = false;
log_error("Failed to connect to the XMPP server: " << reason);
#ifdef SYSTEMDDAEMON_FOUND
sd_notifyf(0, "STATUS=Failed to connect to the XMPP server: %s", reason.data());
@@ -95,6 +97,7 @@ void XmppComponent::on_connection_failed(const std::string& reason)
void XmppComponent::on_connected()
{
log_info("connected to XMPP server");
+ this->first_connection_try = true;
XmlNode node("", nullptr);
node.set_name("stream:stream");
node["xmlns"] = COMPONENT_NS;
diff --git a/src/xmpp/xmpp_component.hpp b/src/xmpp/xmpp_component.hpp
index 64b2ff7..951d5a3 100644
--- a/src/xmpp/xmpp_component.hpp
+++ b/src/xmpp/xmpp_component.hpp
@@ -241,6 +241,12 @@ public:
* Whether or not we ever succeeded our authentication to the XMPP server
*/
bool ever_auth;
+ /**
+ * Whether or not this is the first consecutive try on connecting to the
+ * XMPP server. We use this to delay the connection attempt for a few
+ * seconds, if it is not the first try.
+ */
+ bool first_connection_try;
private:
/**