Software / code / prosody
Comparison
plugins/mod_smacks.lua @ 12068:c3790ffdf467
mod_smacks: Remove useless delay in requesting ack on resumption
Was this the last place using the delay? Nice!
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Fri, 17 Dec 2021 17:22:27 +0100 |
| parent | 12067:97c377de8083 |
| child | 12069:b9e08cbd032b |
comparison
equal
deleted
inserted
replaced
| 12067:97c377de8083 | 12068:c3790ffdf467 |
|---|---|
| 139 end | 139 end |
| 140 | 140 |
| 141 local function request_ack_now_if_needed(session, force, reason) | 141 local function request_ack_now_if_needed(session, force, reason) |
| 142 if should_ack(session, force) then | 142 if should_ack(session, force) then |
| 143 request_ack(session, reason); | 143 request_ack(session, reason); |
| 144 end | |
| 145 end | |
| 146 | |
| 147 local function request_ack_if_needed(session, force, reason, stanza) | |
| 148 if should_ack(session, force) then | |
| 149 timer.add_task(0, function () | |
| 150 request_ack_now_if_needed(session, force, reason, stanza); | |
| 151 end); | |
| 152 end | |
| 153 | |
| 154 -- Trigger "smacks-ack-delayed"-event if we added new (ackable) stanzas to the outgoing queue | |
| 155 -- and there isn't already a timer for this event running. | |
| 156 -- If we wouldn't do this, stanzas added to the queue after the first "smacks-ack-delayed"-event | |
| 157 -- would not trigger this event (again). | |
| 158 local queue = session.outgoing_stanza_queue; | |
| 159 local max_unacked = max_unacked_stanzas; | |
| 160 if session.state == "inactive" then | |
| 161 max_unacked = max_inactive_unacked_stanzas; | |
| 162 end | |
| 163 if queue:count_unacked() > max_unacked and session.awaiting_ack and session.delayed_ack_timer == nil then | |
| 164 session.log("debug", "Calling ack_delayed directly (still waiting for ack)"); | |
| 165 ack_delayed(session, stanza); -- this is the only new stanza in the queue --> provide it to other modules | |
| 166 end | 144 end |
| 167 end | 145 end |
| 168 | 146 |
| 169 local function outgoing_stanza_filter(stanza, session) | 147 local function outgoing_stanza_filter(stanza, session) |
| 170 -- XXX: Normally you wouldn't have to check the xmlns for a stanza as it's | 148 -- XXX: Normally you wouldn't have to check the xmlns for a stanza as it's |
| 589 migrated_session_log("error", "Tried to send stanza on old session migrated by smacks resume (maybe there is a bug?): %s", tostring(stanza)); | 567 migrated_session_log("error", "Tried to send stanza on old session migrated by smacks resume (maybe there is a bug?): %s", tostring(stanza)); |
| 590 return false; | 568 return false; |
| 591 end | 569 end |
| 592 module:fire_event("smacks-hibernation-end", {origin = session, resumed = original_session, queue = queue:table()}); | 570 module:fire_event("smacks-hibernation-end", {origin = session, resumed = original_session, queue = queue:table()}); |
| 593 original_session.awaiting_ack = nil; -- Don't wait for acks from before the resumption | 571 original_session.awaiting_ack = nil; -- Don't wait for acks from before the resumption |
| 594 request_ack_if_needed(original_session, true, "handle_resume", nil); | 572 request_ack_now_if_needed(original_session, true, "handle_resume", nil); |
| 595 end | 573 end |
| 596 return true; | 574 return true; |
| 597 end | 575 end |
| 598 module:hook_tag(xmlns_sm2, "resume", function (session, stanza) return handle_resume(session, stanza, xmlns_sm2); end); | 576 module:hook_tag(xmlns_sm2, "resume", function (session, stanza) return handle_resume(session, stanza, xmlns_sm2); end); |
| 599 module:hook_tag(xmlns_sm3, "resume", function (session, stanza) return handle_resume(session, stanza, xmlns_sm3); end); | 577 module:hook_tag(xmlns_sm3, "resume", function (session, stanza) return handle_resume(session, stanza, xmlns_sm3); end); |