synchronize stanza count increment and write

This commit is contained in:
Daniel Gultsch 2016-06-22 12:21:33 +02:00
parent 4d1640d6ff
commit 34454ef2ec
1 changed files with 11 additions and 11 deletions

View File

@ -1024,9 +1024,9 @@ public class XmppConnection implements Runnable {
smVersion = 2; smVersion = 2;
} }
if (smVersion != 0) { if (smVersion != 0) {
final EnablePacket enable = new EnablePacket(smVersion);
tagWriter.writeStanzaAsync(enable);
synchronized (this.mStanzaQueue) { synchronized (this.mStanzaQueue) {
final EnablePacket enable = new EnablePacket(smVersion);
tagWriter.writeStanzaAsync(enable);
stanzasSent = 0; stanzasSent = 0;
mStanzaQueue.clear(); mStanzaQueue.clear();
} }
@ -1261,18 +1261,18 @@ public class XmppConnection implements Runnable {
disconnect(true); disconnect(true);
return; return;
} }
tagWriter.writeStanzaAsync(packet); synchronized (this.mStanzaQueue) {
if (packet instanceof AbstractAcknowledgeableStanza) { tagWriter.writeStanzaAsync(packet);
AbstractAcknowledgeableStanza stanza = (AbstractAcknowledgeableStanza) packet; if (packet instanceof AbstractAcknowledgeableStanza) {
synchronized (this.mStanzaQueue) { AbstractAcknowledgeableStanza stanza = (AbstractAcknowledgeableStanza) packet;
++stanzasSent; ++stanzasSent;
this.mStanzaQueue.append(stanzasSent, stanza); this.mStanzaQueue.append(stanzasSent, stanza);
} if (stanza instanceof MessagePacket && stanza.getId() != null && getFeatures().sm()) {
if (stanza instanceof MessagePacket && stanza.getId() != null && getFeatures().sm()) { if (Config.EXTENDED_SM_LOGGING) {
if (Config.EXTENDED_SM_LOGGING) { Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": requesting ack for message stanza #" + stanzasSent);
Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": requesting ack for message stanza #" + stanzasSent); }
tagWriter.writeStanzaAsync(new RequestPacket(this.smVersion));
} }
tagWriter.writeStanzaAsync(new RequestPacket(this.smVersion));
} }
} }
} }