# HG changeset patch # User tmolitor # Date 1560555292 -7200 # Node ID fb1c8dee2ead4f2eca2a3013c772ce5992ab935c # Parent 74aa35aeb08ab155d570c4af7113ceeba662cdf2 mod_smacks: piggyback ack request onto ack response if queue is not empty, use native stoppable timers if supported diff -r 74aa35aeb08a -r fb1c8dee2ead mod_smacks/mod_smacks.lua --- a/mod_smacks/mod_smacks.lua Sat Jun 15 01:26:15 2019 +0200 +++ b/mod_smacks/mod_smacks.lua Sat Jun 15 01:34:52 2019 +0200 @@ -104,12 +104,14 @@ local function stoppable_timer(delay, callback) local stopped = false; + local timer = module:add_timer(delay, function (t) + if stopped then return; end + return callback(t); + end); + if timer.stop then return timer; end -- new prosody api includes stop() function return { stop = function () stopped = true end; - module:add_timer(delay, function (t) - if stopped then return; end - return callback(t); - end); + timer; }; end @@ -207,6 +209,7 @@ queue[#queue+1] = cached_stanza; if session.hibernating then session.log("debug", "hibernating, stanza queued"); + module:fire_event("smacks-hibernation-stanza-queued", {origin = session, queue = queue, stanza = cached_stanza}); return nil; end request_ack_if_needed(session, false, "outgoing_stanza_filter"); @@ -326,6 +329,10 @@ module:log("debug", "Received ack request, acking for %d", origin.handled_stanza_count); -- Reply with (origin.sends2s or origin.send)(st.stanza("a", { xmlns = xmlns_sm, h = string.format("%d", origin.handled_stanza_count) })); + -- piggyback our own ack request + if #origin.outgoing_stanza_queue > 0 and origin.last_queue_count ~= #origin.outgoing_stanza_queue then + request_ack_if_needed(origin, true, "piggybacked by handle_r"); + end return true; end module:hook_stanza(xmlns_sm2, "r", function (origin, stanza) return handle_r(origin, stanza, xmlns_sm2); end);