Mon, 10 Sep 2018 14:56:12 +0100
client: Add _finish handler to disconnect from server if still connected
scansion/objects/client.lua | file | annotate | diff | comparison | revisions |
--- a/scansion/objects/client.lua Mon Sep 10 14:55:43 2018 +0100 +++ b/scansion/objects/client.lua Mon Sep 10 14:56:12 2018 +0100 @@ -52,13 +52,20 @@ client.stream:hook("stanza", function (s) client.log("Stanza: %s", s) end); -- Handle unexpected disconnects client.stream:hook("disconnected", function (s) - if not (client.disconnect_expected or client.script.finished) or s.reason then + if not (client.disconnect_expected or client.script.finished) or (s.reason and s.reason ~= "stream closed" and s.reason ~= "closed") then client.log("Unexpected disconnect!"); error("Unexpected disconnect"..(s.reason and " ("..tostring(s.reason)..")" or "")); end end); end; + _finish = function (client) + if client.stream.connected then + client.disconnect_expected = true; + client.stream:close(); + end + end; + connects = function (client) local wait, done = async.waiter(); client.stream:hook("ready", function ()