Skip to content

Commit

Permalink
pinger: only send once until last one returns
Browse files Browse the repository at this point in the history
  • Loading branch information
ge0rg committed Feb 5, 2013
1 parent cb06232 commit 445f1bb
Showing 1 changed file with 5 additions and 13 deletions.
18 changes: 5 additions & 13 deletions src/org/yaxim/androidclient/service/SmackableImp.java
Expand Up @@ -16,6 +16,7 @@
import org.jivesoftware.smack.SmackConfiguration;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.filter.IQTypeFilter;
import org.jivesoftware.smack.filter.PacketFilter;
import org.jivesoftware.smack.filter.PacketTypeFilter;
import org.jivesoftware.smack.packet.IQ;
Expand Down Expand Up @@ -595,6 +596,8 @@ public void changeMessageDeliveryStatus(String packetID, int new_status) {
}

public void sendServerPing() {
if (mPingID != null)
return; // a ping is still on its way
Ping ping = new Ping();
ping.setType(Type.GET);
ping.setTo(mConfig.server);
Expand Down Expand Up @@ -643,18 +646,6 @@ private void registerPongListener() {
if (mPongListener != null)
mXMPPConnection.removePacketListener(mPongListener);

PacketFilter filter = new PacketFilter() {

@Override
public boolean accept(Packet packet) {
if ((packet instanceof IQ)) {
debugLog("got IQ packet with ID: " + packet.getPacketID());
return true;
}
return false;
}
};

mPongListener = new PacketListener() {

@Override
Expand All @@ -664,13 +655,14 @@ public void processPacket(Packet packet) {
if (packet.getPacketID().equals(mPingID)) {
debugLog("got Pong");
Log.i(TAG, String.format("Server latency: %1.3fs", (System.currentTimeMillis() - mPingTimestamp)/1000.));
mPingID = null;
((AlarmManager)mService.getSystemService(Context.ALARM_SERVICE)).cancel(mPongTimeoutAlarmPendIntent);
}
}

};

mXMPPConnection.addPacketListener(mPongListener, filter);
mXMPPConnection.addPacketListener(mPongListener, new IQTypeFilter(IQ.Type.RESULT));
mPingAlarmPendIntent = PendingIntent.getBroadcast(mService.getApplicationContext(), 0, mPingAlarmIntent,
PendingIntent.FLAG_UPDATE_CURRENT);
mPongTimeoutAlarmPendIntent = PendingIntent.getBroadcast(mService.getApplicationContext(), 0, mPongTimeoutAlarmIntent,
Expand Down

0 comments on commit 445f1bb

Please sign in to comment.