aboutsummaryrefslogtreecommitdiff
path: root/libdino/src/service/connection_manager.vala
diff options
context:
space:
mode:
authorfiaxh <git@lightrise.org>2019-11-27 18:46:29 +0100
committerfiaxh <git@lightrise.org>2019-11-27 20:01:48 +0100
commit1985fe1d7b94bd1eff80bb3da14bbc52e5585163 (patch)
treef908b8bafdfc8166a6c60159ee7eb6a9a4389078 /libdino/src/service/connection_manager.vala
parentc4325473fba84db6d48bf2ca9e79214fef1cca2f (diff)
downloaddino-1985fe1d7b94bd1eff80bb3da14bbc52e5585163.tar.gz
dino-1985fe1d7b94bd1eff80bb3da14bbc52e5585163.zip
Don't continue reading after stream was disconnected, make disconnecting async
fixes #636
Diffstat (limited to 'libdino/src/service/connection_manager.vala')
-rw-r--r--libdino/src/service/connection_manager.vala25
1 files changed, 16 insertions, 9 deletions
diff --git a/libdino/src/service/connection_manager.vala b/libdino/src/service/connection_manager.vala
index 0a129717..000a4bfa 100644
--- a/libdino/src/service/connection_manager.vala
+++ b/libdino/src/service/connection_manager.vala
@@ -131,11 +131,11 @@ public class ConnectionManager : Object {
connections[account].stream.get_module(Presence.Module.IDENTITY).send_presence(connections[account].stream, presence);
}
- public void disconnect_account(Account account) {
+ public async void disconnect_account(Account account) {
if (connections.has_key(account)) {
make_offline(account);
try {
- connections[account].stream.disconnect();
+ yield connections[account].stream.disconnect();
} catch (Error e) {
debug("Error disconnecting stream: %s", e.message);
}
@@ -217,6 +217,8 @@ public class ConnectionManager : Object {
}
private void check_reconnect(Account account) {
+ if (!connections.has_key(account)) return;
+
bool acked = false;
DateTime? last_activity_was = connections[account].last_activity;
@@ -228,6 +230,7 @@ public class ConnectionManager : Object {
});
Timeout.add_seconds(10, () => {
+ if (!connections.has_key(account)) return false;
if (connections[account].stream != stream) return false;
if (acked) return false;
if (connections[account].last_activity != last_activity_was) return false;
@@ -235,11 +238,15 @@ public class ConnectionManager : Object {
// Reconnect. Nothing gets through the stream.
debug("[%s %p] Ping timeouted. Reconnecting", account.bare_jid.to_string(), stream);
change_connection_state(account, ConnectionState.DISCONNECTED);
- try {
- connections[account].stream.disconnect();
- } catch (Error e) {
- debug("Error disconnecting stream: %s", e.message);
- }
+
+ connections[account].stream.disconnect.begin((_, res) => {
+ try {
+ connections[account].stream.disconnect.end(res);
+ } catch (Error e) {
+ debug("Error disconnecting stream: %s", e.message);
+ }
+ });
+
connect_(account);
return false;
});
@@ -267,7 +274,7 @@ public class ConnectionManager : Object {
}
}
- private void on_prepare_for_sleep(bool suspend) {
+ private async void on_prepare_for_sleep(bool suspend) {
foreach (Account account in connection_todo) {
change_connection_state(account, ConnectionState.DISCONNECTED);
}
@@ -276,7 +283,7 @@ public class ConnectionManager : Object {
foreach (Account account in connection_todo) {
try {
make_offline(account);
- connections[account].stream.disconnect();
+ yield connections[account].stream.disconnect();
} catch (Error e) {
debug("Error disconnecting stream %p: %s", connections[account].stream, e.message);
}