From b9b43ad5d788ccd07f77e88c7a56a0e1bbbc3e1f Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Wed, 20 Aug 2014 10:44:02 +0200 Subject: [PATCH] Make the next server ping code easier to read --- .../org/jivesoftware/smackx/ping/PingManager.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) 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 7f50f6ad2..ee5dc2244 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 @@ -301,7 +301,7 @@ public class PingManager extends Manager { * Cancels any existing periodic ping task if there is one and schedules a new ping task if * pingInterval is greater then zero. * - * @param delta the delta to the last received ping in seconds + * @param delta the delta to the last received stanza in seconds */ private synchronized void maybeSchedulePingServerTask(int delta) { maybeStopPingServerTask(); @@ -339,11 +339,11 @@ public class PingManager extends Manager { long lastStanzaReceived = connection.getLastStanzaReceived(); if (lastStanzaReceived > 0) { long now = System.currentTimeMillis(); - // Calculate the delta from now to the next ping time. If delta is positive, the - // last successful ping was not to long ago, so we can defer the current ping. - int delta = (int) (((pingInterval * 1000) - (now - lastStanzaReceived)) / 1000); - if (delta > 0) { - maybeSchedulePingServerTask(delta); + // Delta since the last stanza was received + int deltaInSeconds = (int) ((now - lastStanzaReceived) / 1000); + // If the delta is small then the ping interval, then we can defer the ping + if (deltaInSeconds < pingInterval) { + maybeSchedulePingServerTask(deltaInSeconds); return; } }