aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Gultsch <daniel@gultsch.de>2016-01-16 19:21:11 +0100
committerDaniel Gultsch <daniel@gultsch.de>2016-01-16 19:21:11 +0100
commit7b1efe15cdb298dc30e50949be6803c4489e18da (patch)
tree8302395b366fe2b76f8251caf16c7e9c890e485b
parent41ae4af1b812f76d1ba13d7c1f99e0f6ec80705b (diff)
reuse same xmppconnection for reconnects
-rw-r--r--src/main/java/eu/siacs/conversations/services/XmppConnectionService.java18
-rw-r--r--src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java8
2 files changed, 17 insertions, 9 deletions
diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java
index 6e3e626a..a295b2ce 100644
--- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java
+++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java
@@ -2451,11 +2451,14 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
private void reconnectAccount(final Account account, final boolean force, final boolean interactive) {
synchronized (account) {
- if (account.getXmppConnection() != null) {
+ XmppConnection connection = account.getXmppConnection();
+ if (connection != null) {
disconnect(account, force);
+ } else {
+ connection = createConnection(account);
+ account.setXmppConnection(connection);
}
if (!account.isOptionSet(Account.OPTION_DISABLED)) {
-
synchronized (this.mInProgressAvatarFetches) {
for (Iterator<String> iterator = this.mInProgressAvatarFetches.iterator(); iterator.hasNext(); ) {
final String KEY = iterator.next();
@@ -2464,10 +2467,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
}
}
}
-
- if (account.getXmppConnection() == null) {
- account.setXmppConnection(createConnection(account));
- } else if (!force) {
+ if (!force) {
try {
Log.d(Config.LOGTAG, "wait for disconnect");
Thread.sleep(500); //sleep wait for disconnect
@@ -2475,13 +2475,13 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
//ignored
}
}
- Thread thread = new Thread(account.getXmppConnection());
- account.getXmppConnection().setInteractive(interactive);
+ Thread thread = new Thread(connection);
+ connection.setInteractive(interactive);
thread.start();
scheduleWakeUpCall(Config.CONNECT_DISCO_TIMEOUT, account.getUuid().hashCode());
} else {
account.getRoster().clearPresences();
- account.setXmppConnection(null);
+ connection.resetEverything();
}
}
}
diff --git a/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java b/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java
index 9e83491f..1f114141 100644
--- a/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java
+++ b/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java
@@ -875,6 +875,14 @@ public class XmppConnection implements Runnable {
+ instructions);
}
+ public void resetEverything() {
+ resetStreamId();
+ clearIqCallbacks();
+ synchronized (this.disco) {
+ disco.clear();
+ }
+ }
+
private void sendBindRequest() {
while(!mXmppConnectionService.areMessagesInitialized() && socket != null && !socket.isClosed()) {
try {