From 1985fe1d7b94bd1eff80bb3da14bbc52e5585163 Mon Sep 17 00:00:00 2001 From: fiaxh Date: Wed, 27 Nov 2019 18:46:29 +0100 Subject: Don't continue reading after stream was disconnected, make disconnecting async fixes #636 --- xmpp-vala/src/core/xmpp_stream.vala | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) (limited to 'xmpp-vala/src/core') 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", ""); - ((!)writer).write.begin(""); - ((!)reader).cancel(); - ((!)stream).close_async.begin(); + yield writer.write(""); + 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") { -- cgit v1.2.3-70-g09d2