From 74f7fa897f9aec298eeadcfc7a7b971f06498858 Mon Sep 17 00:00:00 2001 From: fiaxh Date: Sun, 28 Jun 2020 15:53:41 +0200 Subject: Add queue and resending to stream management --- xmpp-vala/src/core/xmpp_stream.vala | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) (limited to 'xmpp-vala/src/core/xmpp_stream.vala') diff --git a/xmpp-vala/src/core/xmpp_stream.vala b/xmpp-vala/src/core/xmpp_stream.vala index 39754ba1..f4cdf09a 100644 --- a/xmpp-vala/src/core/xmpp_stream.vala +++ b/xmpp-vala/src/core/xmpp_stream.vala @@ -18,12 +18,14 @@ public class XmppStream { public StanzaNode? features { get; private set; default = new StanzaNode.build("features", NS_URI); } private IOStream? stream; - private StanzaReader? reader; - private StanzaWriter? writer; + internal StanzaReader? reader; + internal StanzaWriter? writer; public Gee.List flags { get; private set; default=new ArrayList(); } public Gee.List modules { get; private set; default=new ArrayList(); } private Gee.List connection_providers = new ArrayList(); + + internal WriteNodeFunc? write_obj = null; public bool negotiation_complete { get; set; default=false; } private bool setup_needed = false; private bool non_negotiation_modules_attached = false; @@ -126,13 +128,17 @@ public class XmppStream { } public async void write_async(StanzaNode node) throws IOStreamError { - StanzaWriter? writer = this.writer; - if (writer == null) throw new IOStreamError.WRITE("trying to write, but no stream open"); - try { - log.node("OUT", node, this); - yield ((!)writer).write_node(node); - } catch (XmlError e) { - throw new IOStreamError.WRITE(e.message); + if (write_obj != null) { + yield write_obj.write_stanza(this, node); + } else { + StanzaWriter? writer = this.writer; + if (writer == null) throw new IOStreamError.WRITE("trying to write, but no stream open"); + try { + log.node("OUT", node, this); + yield ((!)writer).write_node(node); + } catch (XmlError e) { + throw new IOStreamError.WRITE(e.message); + } } } @@ -403,4 +409,8 @@ public class StartTlsConnectionProvider : ConnectionProvider { public override string get_id() { return "start_tls"; } } +public interface WriteNodeFunc : Object { + public abstract async void write_stanza(XmppStream stream, StanzaNode node) throws IOError; +} + } -- cgit v1.2.3-70-g09d2