Skip to content

Commit

Permalink
XEP-0198: increase buffers, unblock tcp!
Browse files Browse the repository at this point in the history
  • Loading branch information
ge0rg committed May 23, 2014
1 parent b1f41ac commit a5955ba
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/org/yaxim/androidclient/service/XmppStreamHandler.java
Expand Up @@ -30,8 +30,8 @@
public class XmppStreamHandler {
private static final String TAG = "yaxim.StreamHandler";
private static final String URN_SM_2 = "urn:xmpp:sm:2";
private static final int MAX_OUTGOING_QUEUE_SIZE = 20;
private static final int OUTGOING_FILL_RATIO = 4;
private static final int MAX_OUTGOING_QUEUE_SIZE = 200;
private static final int REQUEST_ACK_AFTER_STANZAS = 10;
private ExtXMPPConnection mConnection;
private boolean isSmAvailable = false;
private boolean isSmEnabled = false;
Expand All @@ -41,6 +41,7 @@ public class XmppStreamHandler {
private String sessionId;
private long incomingStanzaCount = 0;
private long outgoingStanzaCount = 0;
private long outgoingStanzasSinceAckRequest = 0;
private Queue<Packet> outgoingQueue;
private int maxOutgoingQueueSize = MAX_OUTGOING_QUEUE_SIZE;

Expand Down Expand Up @@ -101,6 +102,7 @@ private void sendEnablePacket() {
}
if (sessionId != null) {
isOutgoingSmEnabled = true;
outgoingStanzasSinceAckRequest = 0;
// TODO binding
Log.d(TAG, "sendResume(): " + sessionId);
StreamHandlingPacket resumePacket = new StreamHandlingPacket("resume", URN_SM_2);
Expand All @@ -110,6 +112,7 @@ private void sendEnablePacket() {
} else {
Log.d(TAG, "sendEnable()");
outgoingStanzaCount = 0;
outgoingStanzasSinceAckRequest = 0;
outgoingQueue = new ConcurrentLinkedQueue<Packet>();
isOutgoingSmEnabled = true;

Expand Down Expand Up @@ -195,10 +198,11 @@ public void processPacket(Packet packet) {
outgoingQueue.add(packet);

if (debugStanzas) Log.d(TAG, "adding " + outgoingStanzaCount + " : " + packet.toXML());
//

outgoingStanzasSinceAckRequest++;
// Don't let the queue grow beyond max size. Request acks and drop old packets
// if acks are not coming.
if (outgoingQueue.size() >= maxOutgoingQueueSize / OUTGOING_FILL_RATIO) {
if (outgoingStanzasSinceAckRequest >= REQUEST_ACK_AFTER_STANZAS) {
requestAck();
}

Expand Down Expand Up @@ -312,6 +316,7 @@ private void removeOutgoingAcked(long ackCount) {
}

public long requestAck() {
outgoingStanzasSinceAckRequest = 0;
mConnection.sendPacket(new StreamHandlingPacket("r", URN_SM_2));
return outgoingStanzaCount;
}
Expand Down

0 comments on commit a5955ba

Please sign in to comment.