From 1fa0e770fe4d6108fe85ca7b49fd0e0b1e545215 Mon Sep 17 00:00:00 2001 From: Clombrong Date: Sun, 29 Jun 2025 05:37:20 +0200 Subject: feat(portal_tcp): send closing element when pushing None --- portal/tcp/portal.ml | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'portal') diff --git a/portal/tcp/portal.ml b/portal/tcp/portal.ml index 31c45c0..c767f3e 100644 --- a/portal/tcp/portal.ml +++ b/portal/tcp/portal.ml @@ -123,8 +123,17 @@ let socket_to_stream (sock : socket) = in let outbound_stream, outbound_push = Lwt_stream.create () in let push = function - | None -> outbound_push None | Some signals -> Markup.iter (fun f -> outbound_push (Some f)) signals + | None -> begin + (* XMPP streams are one long XML document, so naturally ending the document + closes the stream. *) + outbound_push (Some `End_element); + Lwt.async + (fun () -> + (* We drain completely the stream when closing, so the socket can close. *) + let+ () = Markup_lwt.drain stream + in outbound_push None) + end in Lwt.async begin fun () -> let* _ = -- cgit v1.2.3