aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java
diff options
context:
space:
mode:
authorDaniel Gultsch <daniel@gultsch.de>2015-10-16 09:58:31 +0200
committerDaniel Gultsch <daniel@gultsch.de>2015-10-16 09:58:31 +0200
commitfb7359e6a3aaa3ee0b985358c044de2a5594d45b (patch)
tree03cb1160b3ae5a884e5aebf68b06c729227482f6 /src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java
parentc1716a35e359cf9b2e8d1b75cc4f0bac413bee5b (diff)
block code when doing unforced disconnect
Diffstat (limited to '')
-rw-r--r--src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java67
1 files changed, 32 insertions, 35 deletions
diff --git a/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java b/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java
index d21682a7..f311688e 100644
--- a/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java
+++ b/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java
@@ -783,7 +783,7 @@ public class XmppConnection implements Runnable {
String urlString = url.findChildContent("value");
URL uri = new URL(urlString);
captcha = BitmapFactory.decodeStream(uri.openConnection().getInputStream());
- } catch(IOException e) {
+ } catch (IOException e) {
Log.e(Config.LOGTAG, e.toString());
}
}
@@ -884,7 +884,7 @@ public class XmppConnection implements Runnable {
public void onIqPacketReceived(Account account, IqPacket packet) {
if (packet.getType() == IqPacket.TYPE.RESULT) {
sendPostBindInitialization();
- } else if (packet.getType() != IqPacket.TYPE.TIMEOUT){
+ } else if (packet.getType() != IqPacket.TYPE.TIMEOUT) {
Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": could not init sessions");
disconnect(true);
}
@@ -1139,44 +1139,41 @@ public class XmppConnection implements Runnable {
}
public void disconnect(final boolean force) {
- Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": disconnecting");
- try {
- if (force) {
+ Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": disconnecting force="+Boolean.valueOf(force));
+ if (force) {
+ try {
socket.close();
- return;
+ } catch(Exception e) {
+ Log.d(Config.LOGTAG,account.getJid().toBareJid().toString()+": exception during force close ("+e.getMessage()+")");
}
- new Thread(new Runnable() {
-
- @Override
- public void run() {
- if (tagWriter.isActive()) {
- tagWriter.finish();
- try {
- int i = 0;
- boolean warned = false;
- while (!tagWriter.finished() && socket.isConnected() && i <= 10) {
- if (!warned) {
- Log.d(Config.LOGTAG, account.getJid().toBareJid()+": waiting for tag writer to finish");
- warned = true;
- }
- Thread.sleep(200);
- i++;
- }
- if (warned) {
- Log.d(Config.LOGTAG,account.getJid().toBareJid()+": tag writer has finished");
- }
- tagWriter.writeTag(Tag.end("stream:stream"));
- socket.close();
- } catch (final IOException e) {
- Log.d(Config.LOGTAG,"io exception during disconnect");
- } catch (final InterruptedException e) {
- Log.d(Config.LOGTAG, "interrupted");
+ return;
+ } else {
+ resetStreamId();
+ if (tagWriter.isActive()) {
+ tagWriter.finish();
+ try {
+ int i = 0;
+ boolean warned = false;
+ while (!tagWriter.finished() && socket.isConnected() && i <= 10) {
+ if (!warned) {
+ Log.d(Config.LOGTAG, account.getJid().toBareJid()+": waiting for tag writer to finish");
+ warned = true;
}
+ Thread.sleep(200);
+ i++;
+ }
+ if (warned) {
+ Log.d(Config.LOGTAG,account.getJid().toBareJid()+": tag writer has finished");
}
+ Log.d(Config.LOGTAG,account.getJid().toBareJid()+": closing stream");
+ tagWriter.writeTag(Tag.end("stream:stream"));
+ socket.close();
+ } catch (final IOException e) {
+ Log.d(Config.LOGTAG,account.getJid().toBareJid()+": io exception during disconnect ("+e.getMessage()+")");
+ } catch (final InterruptedException e) {
+ Log.d(Config.LOGTAG, "interrupted");
}
- }).start();
- } catch (final IOException e) {
- Log.d(Config.LOGTAG, "io exception during disconnect");
+ }
}
}