make sure tagwriter is clear before force closing socket

This commit is contained in:
Daniel Gultsch 2016-06-13 19:05:32 +02:00
parent 587fb3cca3
commit 40f81f19df
2 changed files with 9 additions and 19 deletions

View file

@ -9,7 +9,6 @@ import eu.siacs.conversations.xmpp.stanzas.AbstractStanza;
public class TagWriter { public class TagWriter {
private OutputStream plainOutputStream;
private OutputStreamWriter outputStream; private OutputStreamWriter outputStream;
private boolean finshed = false; private boolean finshed = false;
private LinkedBlockingQueue<AbstractStanza> writeQueue = new LinkedBlockingQueue<AbstractStanza>(); private LinkedBlockingQueue<AbstractStanza> writeQueue = new LinkedBlockingQueue<AbstractStanza>();
@ -24,15 +23,9 @@ public class TagWriter {
} }
try { try {
AbstractStanza output = writeQueue.take(); AbstractStanza output = writeQueue.take();
if (outputStream == null) {
shouldStop = true;
} else {
outputStream.write(output.toString()); outputStream.write(output.toString());
outputStream.flush(); outputStream.flush();
} } catch (Exception e) {
} catch (IOException e) {
shouldStop = true;
} catch (InterruptedException e) {
shouldStop = true; shouldStop = true;
} }
} }
@ -46,17 +39,9 @@ public class TagWriter {
if (out == null) { if (out == null) {
throw new IOException(); throw new IOException();
} }
this.plainOutputStream = out;
this.outputStream = new OutputStreamWriter(out); this.outputStream = new OutputStreamWriter(out);
} }
public OutputStream getOutputStream() throws IOException {
if (this.plainOutputStream == null) {
throw new IOException();
}
return this.plainOutputStream;
}
public TagWriter beginDocument() throws IOException { public TagWriter beginDocument() throws IOException {
if (outputStream == null) { if (outputStream == null) {
throw new IOException("output stream was null"); throw new IOException("output stream was null");
@ -111,4 +96,9 @@ public class TagWriter {
public boolean isActive() { public boolean isActive() {
return outputStream != null; return outputStream != null;
} }
public void forceClose() {
finish();
outputStream = null;
}
} }

View file

@ -1356,8 +1356,8 @@ public class XmppConnection implements Runnable {
interrupt(); interrupt();
Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": disconnecting force="+Boolean.valueOf(force)); Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": disconnecting force="+Boolean.valueOf(force));
if (force) { if (force) {
tagWriter.forceClose();
forceCloseSocket(); forceCloseSocket();
return;
} else { } else {
if (tagWriter.isActive()) { if (tagWriter.isActive()) {
tagWriter.finish(); tagWriter.finish();