client: Ignore timeout timer if we received a stanza

Sun, 30 Dec 2018 09:43:36 +0000

author
Matthew Wild <mwild1@gmail.com>
date
Sun, 30 Dec 2018 09:43:36 +0000
changeset 164
14500a149b31
parent 163
0e2150680a25
child 165
92e1733243d5

client: Ignore timeout timer if we received a stanza

scansion/objects/client.lua file | annotate | diff | comparison | revisions
--- a/scansion/objects/client.lua	Sat Dec 29 02:52:55 2018 -0500
+++ b/scansion/objects/client.lua	Sun Dec 30 09:43:36 2018 +0000
@@ -95,11 +95,13 @@
 	receives = function (client, data)
 		local wait, done = async.waiter();
 		local expected_stanza = false;
+		local have_received_stanza = false;
 		data = table.concat(data):gsub("\t", "    "):gsub("^%s+", ""):gsub("%s+$", "");
 		if data ~= "nothing" then
 			expected_stanza = fill_vars(client.script, assert(parse_xml(data)));
 		end
 		local function stanza_handler(received_stanza)
+			have_received_stanza = true;
 			if not expected_stanza then
 				error(new_error("unexpected-stanza", {
 					text = "Received unexpected stanza";
@@ -129,6 +131,7 @@
 		end
 		client.stream:hook("stanza", stanza_handler, 100);
 		verse.add_task(client.stanza_timeout or default_stanza_timeout, function ()
+			if have_received_stanza then return; end
 			if expected_stanza then
 				client.log("TIMEOUT waiting for %s", expected_stanza)
 				local e = new_error("stanza-timeout", { text = "Timed out waiting for stanza" });

mercurial