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”.
This commit is contained in:
Florent Le Coz
2015-02-21 06:45:11 +01:00
parent 3032dc3580
commit a50ca30e76
6 changed files with 38 additions and 4 deletions
+4 -1
View File
@@ -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));