changeset 2495:5ca2470a7755

merged upstream changes
author tmolitor <thilo@eightysoft.de>
date Sun, 12 Feb 2017 21:24:08 +0100
parents d300ae5dba87 (diff) a6486881fe42 (current diff)
children e6a3bdbce7b9
files
diffstat 1 files changed, 12 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/mod_smacks/mod_smacks.lua	Sun Feb 12 17:05:44 2017 +0100
+++ b/mod_smacks/mod_smacks.lua	Sun Feb 12 21:24:08 2017 +0100
@@ -43,10 +43,11 @@
 
 local function delayed_ack_function(session)
 	-- fire event only when configured to do so
-	if delayed_ack_timeout > 0 and session.awaiting_ack and not session.outgoing_stanza_queue == nil then
+	if delayed_ack_timeout > 0 and session.awaiting_ack and not (session.outgoing_stanza_queue == nil) then
 		session.log("debug", "Firing event 'smacks-ack-delayed', queue = %d", #session.outgoing_stanza_queue);
 		module:fire_event("smacks-ack-delayed", {origin = session, queue = session.outgoing_stanza_queue});
 	end
+	session.delayed_ack_timer = nil;
 end
 
 local function can_do_smacks(session, advertise_only)
@@ -97,6 +98,14 @@
 			end
 		end);
 	end
+	-- Trigger "smacks-ack-delayed"-event if we added new (ackable) stanzas to the outgoing queue
+	-- and there isn't already a timer for this event running.
+	-- If we wouldn't do this, stanzas added to the queue after the first "smacks-ack-delayed"-event
+	-- would not trigger this event (again).
+	if #queue > max_unacked_stanzas and session.awaiting_ack and session.delayed_ack_timer == nil then
+		session.log("debug", "Calling delayed_ack_function directly (still waiting for ack)");
+		delayed_ack_function(session);
+	end
 end
 
 local function outgoing_stanza_filter(stanza, session)
@@ -241,6 +250,7 @@
 	end
 	if origin.delayed_ack_timer then
 		origin.delayed_ack_timer:stop();
+		origin.delayed_ack_timer = nil;
 	end
 	-- Remove handled stanzas from outgoing_stanza_queue
 	log("debug", "ACK: h=%s, last=%s", stanza.attr.h or "", origin.last_acknowledged_stanza or "");
@@ -430,6 +440,7 @@
 			end
 			if session.delayed_ack_timer then
 				session.delayed_ack_timer:stop();
+				session.delayed_ack_timer = nil;
 			end
 			return false; -- Kick the session
 		end