only force close tagwriter before creating a new one

This commit is contained in:
Daniel Gultsch 2017-02-13 13:01:00 +01:00
parent 6b81ff70e5
commit c8f97be68e
2 changed files with 7 additions and 6 deletions

View File

@ -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()) {

View File

@ -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();