summaryrefslogtreecommitdiff
path: root/src/network
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/network
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/network')
-rw-r--r--src/network/poller.cpp3
-rw-r--r--src/network/tcp_socket_handler.cpp5
2 files changed, 6 insertions, 2 deletions
diff --git a/src/network/poller.cpp b/src/network/poller.cpp
index 29c4bce..ffc4f2d 100644
--- a/src/network/poller.cpp
+++ b/src/network/poller.cpp
@@ -1,5 +1,6 @@
#include <network/poller.hpp>
#include <logger/logger.hpp>
+#include <utils/timed_events.hpp>
#include <assert.h>
#include <errno.h>
@@ -133,7 +134,7 @@ void Poller::stop_watching_send_events(SocketHandler* socket_handler)
int Poller::poll(const std::chrono::milliseconds& timeout)
{
- if (this->socket_handlers.empty())
+ if (this->socket_handlers.empty() && timeout == utils::no_timeout)
return -1;
#if POLLER == POLL
int nb_events = ::poll(this->fds, this->nfds, timeout.count());
diff --git a/src/network/tcp_socket_handler.cpp b/src/network/tcp_socket_handler.cpp
index c5d254e..1d1eaa7 100644
--- a/src/network/tcp_socket_handler.cpp
+++ b/src/network/tcp_socket_handler.cpp
@@ -213,8 +213,11 @@ ssize_t TCPSocketHandler::do_recv(void* recv_buf, const size_t buf_size)
else if (-1 == size)
{
log_warning("Error while reading from socket: " << strerror(errno));
+ // Remember if we were connecting, or already connected when this
+ // happened, because close() sets this->connecting to false
+ const auto were_connecting = this->connecting;
this->close();
- if (this->connecting)
+ if (were_connecting)
this->on_connection_failed(strerror(errno));
else
this->on_connection_close(strerror(errno));