use helper method to close socket

This commit is contained in:
Daniel Gultsch 2019-07-04 10:12:08 +02:00
parent e9099acd97
commit 98c4e9056f
4 changed files with 14 additions and 15 deletions

View file

@ -610,7 +610,7 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece
} else { } else {
serverMsgIdUpdated = false; serverMsgIdUpdated = false;
} }
Log.d(Config.LOGTAG, "skipping duplicate message with " + message.getCounterpart() + ". serverMsgIdUpdated=" + Boolean.toString(serverMsgIdUpdated)); Log.d(Config.LOGTAG, "skipping duplicate message with " + message.getCounterpart() + ". serverMsgIdUpdated=" + serverMsgIdUpdated);
return; return;
} }
} }

View file

@ -341,7 +341,7 @@ public class FileBackend {
} }
} }
public static void close(Closeable stream) { public static void close(final Closeable stream) {
if (stream != null) { if (stream != null) {
try { try {
stream.close(); stream.close();
@ -350,7 +350,7 @@ public class FileBackend {
} }
} }
public static void close(Socket socket) { public static void close(final Socket socket) {
if (socket != null) { if (socket != null) {
try { try {
socket.close(); socket.close();

View file

@ -6,14 +6,15 @@ import android.util.Xml;
import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException; import org.xmlpull.v1.XmlPullParserException;
import java.io.Closeable;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import eu.siacs.conversations.Config; import eu.siacs.conversations.Config;
public class XmlReader { public class XmlReader implements Closeable {
private XmlPullParser parser; private final XmlPullParser parser;
private InputStream is; private InputStream is;
public XmlReader() { public XmlReader() {
@ -48,6 +49,11 @@ public class XmlReader {
} }
} }
@Override
public void close() {
this.is = null;
}
public Tag readTag() throws IOException { public Tag readTag() throws IOException {
try { try {
while (this.is != null && parser.next() != XmlPullParser.END_DOCUMENT) { while (this.is != null && parser.next() != XmlPullParser.END_DOCUMENT) {

View file

@ -1460,15 +1460,8 @@ public class XmppConnection implements Runnable {
} }
private void forceCloseSocket() { private void forceCloseSocket() {
if (socket != null) { FileBackend.close(this.socket);
try { FileBackend.close(this.tagReader);
socket.close();
} catch (IOException e) {
Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": io exception " + e.getMessage() + " during force close");
}
} else {
Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": socket was null during force close");
}
} }
public void interrupt() { public void interrupt() {
@ -1479,7 +1472,7 @@ public class XmppConnection implements Runnable {
public void disconnect(final boolean force) { public void disconnect(final boolean force) {
interrupt(); interrupt();
Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": disconnecting force=" + Boolean.toString(force)); Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": disconnecting force=" + force);
if (force) { if (force) {
forceCloseSocket(); forceCloseSocket();
} else { } else {