Tue, 10 Jul 2018 11:01:56 +0100
client: Detect unexpected disconnects more reliably
scansion/objects/client.lua | file | annotate | diff | comparison | revisions |
--- a/scansion/objects/client.lua Tue Jul 10 11:00:50 2018 +0100 +++ b/scansion/objects/client.lua Tue Jul 10 11:01:56 2018 +0100 @@ -52,8 +52,10 @@ client.stream:hook("stanza", function (s) client.log("Stanza: %s", s) end); -- Handle unexpected disconnects client.stream:hook("disconnected", function (s) - client.log("Unexpected disconnect!"); - error("Unexpected disconnect"); + if not (client.disconnect_expected or client.script.finished) or s.reason then + client.log("Unexpected disconnect!"); + error("Unexpected disconnect"..(s.reason and " ("..tostring(s.reason)..")" or "")); + end end); end; @@ -108,6 +110,7 @@ expected_stanza = nil; client.stream:unhook("stanza", stanza_handler); client.stream.conn:pause(); + client.log("Calling done") done(); end client.stream:hook("stanza", stanza_handler, 100); @@ -126,6 +129,7 @@ end; disconnects = function (client) + client.disconnect_expected = true; client.stream:close(); end; }