diff options
author | fiaxh <git@lightrise.org> | 2024-08-19 12:17:23 +0200 |
---|---|---|
committer | fiaxh <git@lightrise.org> | 2024-08-19 12:28:45 +0200 |
commit | dc57561dcffda62d01618c72e0bbf5c5a45c2114 (patch) | |
tree | f2336f1d6bef1b1a7b37577d444c4141a51fbc39 /xmpp-vala/src/core/stanza_writer.vala | |
parent | 88376cd6f75d5057caa6582d0a82fc76bb7b388f (diff) | |
download | dino-dc57561dcffda62d01618c72e0bbf5c5a45c2114.tar.gz dino-dc57561dcffda62d01618c72e0bbf5c5a45c2114.zip |
Add cancellable to stream connect
Diffstat (limited to 'xmpp-vala/src/core/stanza_writer.vala')
-rw-r--r-- | xmpp-vala/src/core/stanza_writer.vala | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/xmpp-vala/src/core/stanza_writer.vala b/xmpp-vala/src/core/stanza_writer.vala index aecf8983..79af402e 100644 --- a/xmpp-vala/src/core/stanza_writer.vala +++ b/xmpp-vala/src/core/stanza_writer.vala @@ -1,19 +1,19 @@ namespace Xmpp { public class StanzaWriter { - public signal void cancel(); - + private Cancellable? connection_cancellable; private OutputStream output; private Queue<SourceFuncWrapper> queue = new Queue<SourceFuncWrapper>(); private bool running = false; - public StanzaWriter.for_stream(OutputStream output) { + public StanzaWriter.for_stream(OutputStream output, Cancellable? cancellable = null) { this.output = output; + this.connection_cancellable = cancellable; } public async void write_node(StanzaNode node, int io_priority = Priority.DEFAULT, Cancellable? cancellable = null) throws IOError { - yield write_data(node.to_xml().data, io_priority, cancellable); + yield write_data(node.to_xml().data, io_priority, cancellable ?? connection_cancellable); } public async void write_nodes(StanzaNode node1, StanzaNode node2, int io_priority = Priority.DEFAULT, Cancellable? cancellable = null) throws IOError { @@ -29,11 +29,11 @@ public class StanzaWriter { concat[i++] = datum; } - yield write_data(concat, io_priority, cancellable); + yield write_data(concat, io_priority, cancellable ?? connection_cancellable); } public async void write(string s, int io_priority = Priority.DEFAULT, Cancellable? cancellable = null) throws IOError { - yield write_data(s.data, io_priority, cancellable); + yield write_data(s.data, io_priority, cancellable ?? connection_cancellable); } private async void write_data(owned uint8[] data, int io_priority = Priority.DEFAULT, Cancellable? cancellable = null) throws IOError { @@ -45,10 +45,12 @@ public class StanzaWriter { try { yield output.write_all_async(data, io_priority, cancellable, null); } catch (IOError e) { - cancel(); + if (!(e is IOError.CANCELLED)) { + connection_cancellable.cancel(); + } throw e; } catch (GLib.Error e) { - cancel(); + connection_cancellable.cancel(); throw new IOError.FAILED("Error in GLib: %s".printf(e.message)); } finally { SourceFuncWrapper? sfw = queue.pop_head(); |