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; package eu.siacs.conversations.xml;
import android.util.Log;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import java.io.OutputStreamWriter; import java.io.OutputStreamWriter;
import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.LinkedBlockingQueue;
import eu.siacs.conversations.Config;
import eu.siacs.conversations.xmpp.stanzas.AbstractStanza; import eu.siacs.conversations.xmpp.stanzas.AbstractStanza;
public class TagWriter { public class TagWriter {
@ -71,6 +74,7 @@ public class TagWriter {
public TagWriter writeStanzaAsync(AbstractStanza stanza) { public TagWriter writeStanzaAsync(AbstractStanza stanza) {
if (finshed) { if (finshed) {
Log.d(Config.LOGTAG,"attempting to write stanza to finished TagWriter");
return this; return this;
} else { } else {
if (!asyncStanzaWriter.isAlive()) { if (!asyncStanzaWriter.isAlive()) {

View File

@ -211,7 +211,6 @@ public class XmppConnection implements Runnable {
this.account = account; this.account = account;
this.wakeLock = service.getPowerManager().newWakeLock( this.wakeLock = service.getPowerManager().newWakeLock(
PowerManager.PARTIAL_WAKE_LOCK, account.getJid().toBareJid().toString()); PowerManager.PARTIAL_WAKE_LOCK, account.getJid().toBareJid().toString());
tagWriter = new TagWriter();
mXmppConnectionService = service; mXmppConnectionService = service;
} }
@ -253,8 +252,6 @@ public class XmppConnection implements Runnable {
try { try {
Socket localSocket; Socket localSocket;
shouldAuthenticate = needsBinding = !account.isOptionSet(Account.OPTION_REGISTER); shouldAuthenticate = needsBinding = !account.isOptionSet(Account.OPTION_REGISTER);
tagReader = new XmlReader(wakeLock);
tagWriter = new TagWriter();
this.changeStatus(Account.State.CONNECTING); this.changeStatus(Account.State.CONNECTING);
final boolean useTor = mXmppConnectionService.useTorToConnect() || account.isOnion(); final boolean useTor = mXmppConnectionService.useTorToConnect() || account.isOnion();
final boolean extended = mXmppConnectionService.showExtendedConnectionOptions(); final boolean extended = mXmppConnectionService.showExtendedConnectionOptions();
@ -451,6 +448,9 @@ public class XmppConnection implements Runnable {
throw new InterruptedException(); throw new InterruptedException();
} }
this.socket = socket; this.socket = socket;
tagReader = new XmlReader(wakeLock);
if (tagWriter != null) tagWriter.forceClose();
tagWriter = new TagWriter();
tagWriter.setOutputStream(socket.getOutputStream()); tagWriter.setOutputStream(socket.getOutputStream());
tagReader.setInputStream(socket.getInputStream()); tagReader.setInputStream(socket.getInputStream());
tagWriter.beginDocument(); tagWriter.beginDocument();
@ -1356,9 +1356,6 @@ public class XmppConnection implements Runnable {
} }
private void forceCloseSocket() { private void forceCloseSocket() {
if (tagWriter != null) {
tagWriter.forceClose();
}
if (socket != null) { if (socket != null) {
try { try {
socket.close(); socket.close();