1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-11-29 07:22:07 +01:00

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.
This commit is contained in:
Heckel 2019-03-13 23:57:15 +01:00
parent 2b9cbb978e
commit 3d3d89612f

View file

@ -447,6 +447,19 @@ public final class PingManager extends Manager {
pingFuture.onError(new ExceptionCallback<Exception>() { pingFuture.onError(new ExceptionCallback<Exception>() {
@Override @Override
public void processException(Exception exception) { 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) { for (PingFailedListener l : pingFailedListeners) {
l.pingFailed(); l.pingFailed();
} }