Merge pull request #296 from MarcelHeckel/PingManager_ConnectionOkOnAnyPacket

PingManager: con. assumed ok for any packed within the ping interval
This commit is contained in:
Florian Schmaus 2019-03-20 20:00:54 +01:00 committed by GitHub
commit 989dbb14e8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 0 deletions

View File

@ -447,6 +447,19 @@ public final class PingManager extends Manager {
pingFuture.onError(new ExceptionCallback<Exception>() {
@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();
}