From c8f97be68e40826bd0e6f17c72e31e40cf6b13c3 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Mon, 13 Feb 2017 13:01:00 +0100 Subject: [PATCH] only force close tagwriter before creating a new one --- src/main/java/eu/siacs/conversations/xml/TagWriter.java | 4 ++++ .../java/eu/siacs/conversations/xmpp/XmppConnection.java | 9 +++------ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/xml/TagWriter.java b/src/main/java/eu/siacs/conversations/xml/TagWriter.java index c0fc1a139..be32ec5f8 100644 --- a/src/main/java/eu/siacs/conversations/xml/TagWriter.java +++ b/src/main/java/eu/siacs/conversations/xml/TagWriter.java @@ -1,10 +1,13 @@ package eu.siacs.conversations.xml; +import android.util.Log; + import java.io.IOException; import java.io.OutputStream; import java.io.OutputStreamWriter; import java.util.concurrent.LinkedBlockingQueue; +import eu.siacs.conversations.Config; import eu.siacs.conversations.xmpp.stanzas.AbstractStanza; public class TagWriter { @@ -71,6 +74,7 @@ public class TagWriter { public TagWriter writeStanzaAsync(AbstractStanza stanza) { if (finshed) { + Log.d(Config.LOGTAG,"attempting to write stanza to finished TagWriter"); return this; } else { if (!asyncStanzaWriter.isAlive()) { diff --git a/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java b/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java index d80f44f47..1caba5208 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java +++ b/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java @@ -211,7 +211,6 @@ public class XmppConnection implements Runnable { this.account = account; this.wakeLock = service.getPowerManager().newWakeLock( PowerManager.PARTIAL_WAKE_LOCK, account.getJid().toBareJid().toString()); - tagWriter = new TagWriter(); mXmppConnectionService = service; } @@ -253,8 +252,6 @@ public class XmppConnection implements Runnable { try { Socket localSocket; shouldAuthenticate = needsBinding = !account.isOptionSet(Account.OPTION_REGISTER); - tagReader = new XmlReader(wakeLock); - tagWriter = new TagWriter(); this.changeStatus(Account.State.CONNECTING); final boolean useTor = mXmppConnectionService.useTorToConnect() || account.isOnion(); final boolean extended = mXmppConnectionService.showExtendedConnectionOptions(); @@ -451,6 +448,9 @@ public class XmppConnection implements Runnable { throw new InterruptedException(); } this.socket = socket; + tagReader = new XmlReader(wakeLock); + if (tagWriter != null) tagWriter.forceClose(); + tagWriter = new TagWriter(); tagWriter.setOutputStream(socket.getOutputStream()); tagReader.setInputStream(socket.getInputStream()); tagWriter.beginDocument(); @@ -1356,9 +1356,6 @@ public class XmppConnection implements Runnable { } private void forceCloseSocket() { - if (tagWriter != null) { - tagWriter.forceClose(); - } if (socket != null) { try { socket.close();