aboutsummaryrefslogtreecommitdiff
path: root/libdino/src
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
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')
-rw-r--r--libdino/src/application.vala2
-rw-r--r--libdino/src/service/connection_manager.vala25
-rw-r--r--libdino/src/service/registration.vala6
-rw-r--r--libdino/src/service/stream_interactor.vala4
4 files changed, 22 insertions, 15 deletions
diff --git a/libdino/src/application.vala b/libdino/src/application.vala
index 23508bf4..9c53d88a 100644
--- a/libdino/src/application.vala
+++ b/libdino/src/application.vala
@@ -117,7 +117,7 @@ public interface Dino.Application : GLib.Application {
protected void remove_connection(Account account) {
if ((get_flags() & ApplicationFlags.IS_SERVICE) == ApplicationFlags.IS_SERVICE) release();
- stream_interactor.disconnect_account(account);
+ stream_interactor.disconnect_account.begin(account);
}
private void restore() {
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);
}
diff --git a/libdino/src/service/registration.vala b/libdino/src/service/registration.vala
index 20ea6063..19eebb05 100644
--- a/libdino/src/service/registration.vala
+++ b/libdino/src/service/registration.vala
@@ -37,7 +37,7 @@ public class Register : StreamInteractionModule, Object{
if (connected_account.equals(account)) {
ret = error.source;
}
- stream_interactor.disconnect_account(account);
+ stream_interactor.disconnect_account.begin(account);
Idle.add((owned)callback);
});
@@ -91,7 +91,7 @@ public class Register : StreamInteractionModule, Object{
yield;
try {
- stream.disconnect();
+ yield stream.disconnect();
} catch (Error e) {}
return ret;
}
@@ -130,7 +130,7 @@ public class Register : StreamInteractionModule, Object{
form = yield stream.get_module(Xep.InBandRegistration.Module.IDENTITY).get_from_server(stream, jid);
}
try {
- stream.disconnect();
+ yield stream.disconnect();
} catch (Error e) {}
return form;
diff --git a/libdino/src/service/stream_interactor.vala b/libdino/src/service/stream_interactor.vala
index d9074fb7..a1770bb8 100644
--- a/libdino/src/service/stream_interactor.vala
+++ b/libdino/src/service/stream_interactor.vala
@@ -29,8 +29,8 @@ public class StreamInteractor : Object {
connection_manager.connect_account(account);
}
- public void disconnect_account(Account account) {
- connection_manager.disconnect_account(account);
+ public async void disconnect_account(Account account) {
+ yield connection_manager.disconnect_account(account);
account_removed(account);
}