# HG changeset patch # User Matthew Wild # Date 1458132947 0 # Node ID 1124758cac7f3214c6b6f03ff238afad6cf10eed # Parent 4454f124465a362e4b0f77ef25f4a4e454653d0f# Parent ea95637cf0419751a90eefefcf8c8a68d6c9db49 Merge diff -r 4454f124465a -r 1124758cac7f mod_smacks/mod_smacks.lua --- a/mod_smacks/mod_smacks.lua Wed Mar 16 12:55:25 2016 +0000 +++ b/mod_smacks/mod_smacks.lua Wed Mar 16 12:55:47 2016 +0000 @@ -85,11 +85,17 @@ session.log("debug", "#queue = %d", #queue); if session.hibernating then session.log("debug", "hibernating, stanza queued"); - return ""; -- Hack to make session.send() not return nil + return nil; end if #queue > max_unacked_stanzas and not session.awaiting_ack then - session.awaiting_ack = true; - return tostring(stanza)..tostring(st.stanza("r", { xmlns = session.smacks })); + session.log("debug", "Queuing (in a moment)"); + session.awaiting_ack_timer = module:add_timer(1e-06, function () + if not session.awaiting_ack then + session.awaiting_ack = true; + session.log("debug", "Sending (after send)"); + (session.sends2s or session.send)(st.stanza("r", { xmlns = session.smacks })) + end + end); end end return stanza; @@ -165,7 +171,7 @@ module:hook_stanza("http://etherx.jabber.org/streams", "features", function (session, stanza) - module:add_timer(0, function () + module:add_timer(1e-6, function () if can_do_smacks(session) then if stanza:get_child("sm", xmlns_sm3) then session.sends2s(st.stanza("enable", sm3_attr)); @@ -210,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); @@ -390,8 +399,12 @@ 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.log("debug", "Sending (read timeout)"); (session.sends2s or session.send)(st.stanza("r", { xmlns = session.smacks })); session.awaiting_ack = true; return true;