Mercurial > prosody-modules
changeset 2494:d300ae5dba87
mod_smacks: Fix some bugs with smacks-ack-delayed event triggering.
The old code had several flaws which are addressed here.
First of all this fixes the if statement guarding the event generation
There where some timing glitches addressed by this commit as well.
author | tmolitor <thilo@eightysoft.de> |
---|---|
date | Sun, 12 Feb 2017 21:23:22 +0100 (2017-02-12) |
parents | 5fbca7de2088 |
children | 5ca2470a7755 |
files | mod_smacks/mod_smacks.lua |
diffstat | 1 files changed, 12 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/mod_smacks/mod_smacks.lua Sun Feb 12 19:27:50 2017 +0100 +++ b/mod_smacks/mod_smacks.lua Sun Feb 12 21:23:22 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