From dc57561dcffda62d01618c72e0bbf5c5a45c2114 Mon Sep 17 00:00:00 2001 From: fiaxh Date: Mon, 19 Aug 2024 12:17:23 +0200 Subject: Add cancellable to stream connect --- xmpp-vala/src/core/stanza_reader.vala | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'xmpp-vala/src/core/stanza_reader.vala') diff --git a/xmpp-vala/src/core/stanza_reader.vala b/xmpp-vala/src/core/stanza_reader.vala index 17f0b7b0..349476ec 100644 --- a/xmpp-vala/src/core/stanza_reader.vala +++ b/xmpp-vala/src/core/stanza_reader.vala @@ -13,7 +13,7 @@ public class StanzaReader { private uint8[] buffer; private int buffer_fill = 0; private int buffer_pos = 0; - private Cancellable cancellable = new Cancellable(); + private Cancellable? cancellable; private NamespaceState ns_state = new NamespaceState(); @@ -26,19 +26,16 @@ public class StanzaReader { this.for_buffer(s.data); } - public StanzaReader.for_stream(InputStream input) { + public StanzaReader.for_stream(InputStream input, Cancellable? cancellable = null) { this.input = input; + this.cancellable = cancellable; buffer = new uint8[BUFFER_MAX]; } - public void cancel() { - cancellable.cancel(); - } - private async void update_buffer() throws IOError { InputStream? input = this.input; if (input == null) throw new IOError.CLOSED("No input stream specified and end of buffer reached."); - if (cancellable.is_cancelled()) throw new IOError.CANCELLED("Input stream is canceled."); + if (cancellable != null && cancellable.is_cancelled()) throw new IOError.CANCELLED("Input stream is canceled."); buffer_fill = (int) yield ((!)input).read_async(buffer, GLib.Priority.DEFAULT, cancellable); if (buffer_fill == 0) throw new IOError.CLOSED("End of input stream reached."); buffer_pos = 0; -- cgit v1.2.3-70-g09d2