aboutsummaryrefslogtreecommitdiff
path: root/xmpp-vala/src/core/io_xmpp_stream.vala
diff options
context:
space:
mode:
authoreerielili <lionel@les-miquelots.net>2024-08-25 13:32:38 +0000
committerGitHub <noreply@github.com>2024-08-25 13:32:38 +0000
commit45755727db79a2935376d24e7bde7eadb0f2f7ca (patch)
tree73715da99c9d980079df6f2d561822364655e04d /xmpp-vala/src/core/io_xmpp_stream.vala
parent62cdea3a5e701c04f3a7fd9d6b5f48e28fef1f72 (diff)
parent51252f74c94c17d56aa75534652bdc5d43a504cb (diff)
downloaddino-45755727db79a2935376d24e7bde7eadb0f2f7ca.tar.gz
dino-45755727db79a2935376d24e7bde7eadb0f2f7ca.zip
Merge branch 'master' into add-yourselfadd-yourself
Diffstat (limited to 'xmpp-vala/src/core/io_xmpp_stream.vala')
-rw-r--r--xmpp-vala/src/core/io_xmpp_stream.vala28
1 files changed, 17 insertions, 11 deletions
diff --git a/xmpp-vala/src/core/io_xmpp_stream.vala b/xmpp-vala/src/core/io_xmpp_stream.vala
index 9c58a46b..1d9d061b 100644
--- a/xmpp-vala/src/core/io_xmpp_stream.vala
+++ b/xmpp-vala/src/core/io_xmpp_stream.vala
@@ -6,32 +6,36 @@ public interface Xmpp.WriteNodeFunc : Object {
public abstract class Xmpp.IoXmppStream : XmppStream {
private IOStream? stream;
+ internal Cancellable cancellable;
internal StanzaReader? reader;
internal StanzaWriter? writer;
internal WriteNodeFunc? write_obj = null;
- protected IoXmppStream(Jid remote_name) {
+ protected IoXmppStream(Jid remote_name, Cancellable? cancellable = null) {
base(remote_name);
+ this.cancellable = cancellable ?? new Cancellable();
+ }
+
+ public void cancel() {
+ cancellable.cancel();
}
public override async void disconnect() throws IOError {
disconnected = true;
+ cancel();
if (writer == null || reader == null || stream == null) {
throw new IOError.CLOSED("trying to disconnect, but no stream open");
}
log.str("OUT", "</stream:stream>", this);
- yield writer.write("</stream:stream>");
- reader.cancel();
+ yield writer.write("</stream:stream>", Priority.LOW, new Cancellable());
yield stream.close_async();
}
public void reset_stream(IOStream stream) {
this.stream = stream;
- reader = new StanzaReader.for_stream(stream.input_stream);
- writer = new StanzaWriter.for_stream(stream.output_stream);
-
- writer.cancel.connect(reader.cancel);
+ reader = new StanzaReader.for_stream(stream.input_stream, cancellable);
+ writer = new StanzaWriter.for_stream(stream.output_stream, cancellable);
require_setup();
}
@@ -48,18 +52,20 @@ public abstract class Xmpp.IoXmppStream : XmppStream {
write_async.begin(node, io_priority, null, (obj, res) => {
try {
write_async.end(res);
- } catch (Error e) { }
+ } catch (Error e) {
+ warning("Error while writing: %s", e.message);
+ }
});
}
public override async void write_async(StanzaNode node, int io_priority = Priority.DEFAULT, Cancellable? cancellable = null) throws IOError {
if (write_obj != null) {
- yield write_obj.write_stanza(this, node, io_priority, cancellable);
+ yield write_obj.write_stanza(this, node, io_priority, cancellable ?? this.cancellable);
} else {
StanzaWriter? writer = this.writer;
if (writer == null) throw new IOError.NOT_CONNECTED("trying to write, but no stream open");
log.node("OUT", node, this);
- yield ((!)writer).write_node(node, io_priority, cancellable);
+ yield ((!)writer).write_node(node, io_priority, cancellable ?? this.cancellable);
}
}
@@ -75,7 +81,7 @@ public abstract class Xmpp.IoXmppStream : XmppStream {
.put_attribute("stream", "http://etherx.jabber.org/streams", XMLNS_URI);
outs.has_nodes = true;
log.node("OUT ROOT", outs, this);
- write(outs);
+ yield write_async(outs, Priority.HIGH, cancellable);
received_root_node(this, yield read_root());
setup_needed = false;