From 3d3d89612f7b4cbbe2c9f0e2eb5e60acd2bb880a Mon Sep 17 00:00:00 2001 From: Heckel Date: Wed, 13 Mar 2019 23:57:15 +0100 Subject: [PATCH] PingManager: Assume server ping successful if stanzas where received We assume that the connection is good even if there was no ping result but a stanzas within the ping interval. In some case we have produced so much load, that the ping result was not delivered in time because so many other packets were delivered before. --- .../org/jivesoftware/smackx/ping/PingManager.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/ping/PingManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/ping/PingManager.java index 76e89369a..89d4b5bb3 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/ping/PingManager.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/ping/PingManager.java @@ -447,6 +447,19 @@ public final class PingManager extends Manager { pingFuture.onError(new ExceptionCallback() { @Override public void processException(Exception exception) { + long lastStanzaReceived = connection.getLastStanzaReceived(); + if (lastStanzaReceived > 0) { + long now = System.currentTimeMillis(); + // Delta since the last stanza was received + int deltaInSeconds = (int) ((now - lastStanzaReceived) / 1000); + // If the delta is smaller then the ping interval, we have got an valid stanza in time + // So not error notification needed + if (deltaInSeconds < pingInterval) { + maybeSchedulePingServerTask(deltaInSeconds); + return; + } + } + for (PingFailedListener l : pingFailedListeners) { l.pingFailed(); }