aboutsummaryrefslogtreecommitdiff
path: root/xmpp-vala/src/core
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 /xmpp-vala/src/core
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 'xmpp-vala/src/core')
-rw-r--r--xmpp-vala/src/core/xmpp_stream.vala23
1 files changed, 14 insertions, 9 deletions
diff --git a/xmpp-vala/src/core/xmpp_stream.vala b/xmpp-vala/src/core/xmpp_stream.vala
index 44ecabb4..820d7ce8 100644
--- a/xmpp-vala/src/core/xmpp_stream.vala
+++ b/xmpp-vala/src/core/xmpp_stream.vala
@@ -27,6 +27,7 @@ public class XmppStream {
public bool negotiation_complete { get; set; default=false; }
private bool setup_needed = false;
private bool non_negotiation_modules_attached = false;
+ private bool disconnected = false;
public signal void received_node(XmppStream stream, StanzaNode node);
public signal void received_root_node(XmppStream stream, StanzaNode node);
@@ -75,15 +76,15 @@ public class XmppStream {
yield loop();
}
- public void disconnect() throws IOStreamError {
- StanzaWriter? writer = this.writer;
- StanzaReader? reader = this.reader;
- IOStream? stream = this.stream;
- if (writer == null || reader == null || stream == null) throw new IOStreamError.DISCONNECT("trying to disconnect, but no stream open");
+ public async void disconnect() throws IOStreamError, XmlError, IOError {
+ disconnected = true;
+ if (writer == null || reader == null || stream == null) {
+ throw new IOStreamError.DISCONNECT("trying to disconnect, but no stream open");
+ }
log.str("OUT", "</stream:stream>");
- ((!)writer).write.begin("</stream:stream>");
- ((!)reader).cancel();
- ((!)stream).close_async.begin();
+ yield writer.write("</stream:stream>");
+ reader.cancel();
+ yield stream.close_async();
}
public void reset_stream(IOStream stream) {
@@ -217,6 +218,8 @@ public class XmppStream {
Idle.add(loop.callback);
yield;
+ if (disconnected) break;
+
received_node(this, node);
if (node.ns_uri == NS_URI && node.name == "features") {
@@ -224,7 +227,9 @@ public class XmppStream {
received_features_node(this);
} else if (node.ns_uri == NS_URI && node.name == "stream" && node.pseudo) {
debug("[%p] Server closed stream", this);
- disconnect();
+ try {
+ yield disconnect();
+ } catch (Error e) {}
return;
} else if (node.ns_uri == JABBER_URI) {
if (node.name == "message") {