Mercurial > prosody-modules
diff mod_smacks/mod_smacks.lua @ 3620:fb1c8dee2ead
mod_smacks: piggyback ack request onto ack response if queue is not empty, use native stoppable timers if supported
author | tmolitor <thilo@eightysoft.de> |
---|---|
date | Sat, 15 Jun 2019 01:34:52 +0200 |
parents | 3d4eefdd950a |
children | c2c851722a8a |
line wrap: on
line diff
--- 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 <a> (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);