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 {
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;
}
}

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) {
try {
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) {
try {
socket.close();

View file

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

View file

@ -1460,15 +1460,8 @@ public class XmppConnection implements Runnable {
}
private void forceCloseSocket() {
if (socket != null) {
try {
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");
}
FileBackend.close(this.socket);
FileBackend.close(this.tagReader);
}
public void interrupt() {
@ -1479,7 +1472,7 @@ public class XmppConnection implements Runnable {
public void disconnect(final boolean force) {
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) {
forceCloseSocket();
} else {