From e7963b698d012f86e1af815cbadb6e751d0fccfa Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Sat, 1 Mar 2014 15:29:35 +0100 Subject: [PATCH] PingManager should notify PingFailedListeners only once Fixes SMACK-548 --- .../jivesoftware/smackx/ping/PingManager.java | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/extensions/src/main/java/org/jivesoftware/smackx/ping/PingManager.java b/extensions/src/main/java/org/jivesoftware/smackx/ping/PingManager.java index 7351c666a..36e49e961 100644 --- a/extensions/src/main/java/org/jivesoftware/smackx/ping/PingManager.java +++ b/extensions/src/main/java/org/jivesoftware/smackx/ping/PingManager.java @@ -215,13 +215,27 @@ public class PingManager { * @return true if a reply was received from the server, false otherwise. */ public boolean pingMyServer() { + return pingMyServer(true); + } + + /** + * Pings the server. This method will return true if the server is reachable. It + * is the equivalent of calling ping with the XMPP domain. + *

+ * Unlike the {@link #ping(String)} case, this method will return true even if + * {@link #isPingSupported(String)} is false. + * + * @param notifyListeners Notify the PingFailedListener in case of error if true + * @return + */ + public boolean pingMyServer(boolean notifyListeners) { Connection connection = weakRefConnection.get(); boolean res = ping(connection.getServiceName()); - if (!res) { + if (res) { + pongReceived(); + } else if (notifyListeners) { for (PingFailedListener l : pingFailedListeners) l.pingFailed(); - } else { - pongReceived(); } return res; } @@ -323,7 +337,7 @@ public class PingManager { return; } } - res = pingMyServer(); + res = pingMyServer(false); // stop when we receive a pong back if (res) { lastSuccessfulAutomaticPing = System.currentTimeMillis();