1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-11-26 05:52:06 +01:00

PingManager should notify PingFailedListeners only once

Fixes SMACK-548
This commit is contained in:
Florian Schmaus 2014-03-01 15:29:35 +01:00
parent a3e64bab18
commit e7963b698d

View file

@ -215,13 +215,27 @@ public class PingManager {
* @return true if a reply was received from the server, false otherwise. * @return true if a reply was received from the server, false otherwise.
*/ */
public boolean pingMyServer() { 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 <code>ping</code> with the XMPP domain.
* <p>
* 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(); Connection connection = weakRefConnection.get();
boolean res = ping(connection.getServiceName()); boolean res = ping(connection.getServiceName());
if (!res) { if (res) {
pongReceived();
} else if (notifyListeners) {
for (PingFailedListener l : pingFailedListeners) for (PingFailedListener l : pingFailedListeners)
l.pingFailed(); l.pingFailed();
} else {
pongReceived();
} }
return res; return res;
} }
@ -323,7 +337,7 @@ public class PingManager {
return; return;
} }
} }
res = pingMyServer(); res = pingMyServer(false);
// stop when we receive a pong back // stop when we receive a pong back
if (res) { if (res) {
lastSuccessfulAutomaticPing = System.currentTimeMillis(); lastSuccessfulAutomaticPing = System.currentTimeMillis();