From 65788389ea9c3e7e7fd2d96b9bb74df31be2a430 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Sat, 27 Jun 2015 14:25:19 +0200 Subject: [PATCH] Reset ReconnectionManager's 'attempts' to 0 on successful reconnects. Fixes SMACK-668. --- .../org/jivesoftware/smack/ReconnectionManager.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/smack-core/src/main/java/org/jivesoftware/smack/ReconnectionManager.java b/smack-core/src/main/java/org/jivesoftware/smack/ReconnectionManager.java index a38cd1715..f14362736 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/ReconnectionManager.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/ReconnectionManager.java @@ -20,6 +20,7 @@ import org.jivesoftware.smack.XMPPException.StreamErrorException; import org.jivesoftware.smack.packet.StreamError; import org.jivesoftware.smack.util.Async; +import java.io.IOException; import java.lang.ref.WeakReference; import java.util.Map; import java.util.Random; @@ -239,8 +240,17 @@ public class ReconnectionManager { if (isReconnectionPossible(connection)) { connection.connect(); } + // TODO Starting with Smack 4.2, connect() will no + // longer login automatically. So change this and the + // previous lines to connection.connect().login() in the + // 4.2, or any later, branch. + if (!connection.isAuthenticated()) { + connection.login(); + } + // Successfully reconnected. + attempts = 0; } - catch (Exception e) { + catch (SmackException | IOException | XMPPException e) { // Fires the failed reconnection notification for (ConnectionListener listener : connection.connectionListeners) { listener.reconnectionFailed(e);