Changeset

2090:1796a022dd29

mod_smacks: Keep timer object around and stop it when needed (trunk only)
author Kim Alvefur <zash@zash.se>
date Wed, 16 Mar 2016 13:29:28 +0100
parents 2089:964b3d649a36
children 2091:ea95637cf041
files mod_smacks/mod_smacks.lua
diffstat 1 files changed, 7 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/mod_smacks/mod_smacks.lua	Wed Mar 16 13:27:40 2016 +0100
+++ b/mod_smacks/mod_smacks.lua	Wed Mar 16 13:29:28 2016 +0100
@@ -89,7 +89,7 @@
 		end
 		if #queue > max_unacked_stanzas and not session.awaiting_ack then
 			session.log("debug", "Queuing <r> (in a moment)");
-			module:add_timer(1e-06, function ()
+			session.awaiting_ack_timer = module:add_timer(1e-06, function ()
 				if not session.awaiting_ack then
 					session.awaiting_ack = true;
 					session.log("debug", "Sending <r> (after send)");
@@ -216,6 +216,9 @@
 function handle_a(origin, stanza)
 	if not origin.smacks then return; end
 	origin.awaiting_ack = nil;
+	if origin.awaiting_ack_timer then
+		origin.awaiting_ack_timer:stop();
+	end
 	-- Remove handled stanzas from outgoing_stanza_queue
 	--log("debug", "ACK: h=%s, last=%s", stanza.attr.h or "", origin.last_acknowledged_stanza or "");
 	local h = tonumber(stanza.attr.h);
@@ -396,6 +399,9 @@
 	local session = event.session;
 	if session.smacks then
 		if session.awaiting_ack then
+			if session.awaiting_ack_timer then
+				session.awaiting_ack_timer:stop();
+			end
 			return false; -- Kick the session
 		end
 		(session.sends2s or session.send)(st.stanza("r", { xmlns = session.smacks }));