Mercurial > prosody-modules
comparison mod_smacks/mod_smacks.lua @ 2090:1796a022dd29
mod_smacks: Keep timer object around and stop it when needed (trunk only)
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Wed, 16 Mar 2016 13:29:28 +0100 |
| parents | 964b3d649a36 |
| children | ea95637cf041 |
comparison
equal
deleted
inserted
replaced
| 2089:964b3d649a36 | 2090:1796a022dd29 |
|---|---|
| 87 session.log("debug", "hibernating, stanza queued"); | 87 session.log("debug", "hibernating, stanza queued"); |
| 88 return nil; | 88 return nil; |
| 89 end | 89 end |
| 90 if #queue > max_unacked_stanzas and not session.awaiting_ack then | 90 if #queue > max_unacked_stanzas and not session.awaiting_ack then |
| 91 session.log("debug", "Queuing <r> (in a moment)"); | 91 session.log("debug", "Queuing <r> (in a moment)"); |
| 92 module:add_timer(1e-06, function () | 92 session.awaiting_ack_timer = module:add_timer(1e-06, function () |
| 93 if not session.awaiting_ack then | 93 if not session.awaiting_ack then |
| 94 session.awaiting_ack = true; | 94 session.awaiting_ack = true; |
| 95 session.log("debug", "Sending <r> (after send)"); | 95 session.log("debug", "Sending <r> (after send)"); |
| 96 (session.sends2s or session.send)(st.stanza("r", { xmlns = session.smacks })) | 96 (session.sends2s or session.send)(st.stanza("r", { xmlns = session.smacks })) |
| 97 end | 97 end |
| 214 module:hook_stanza(xmlns_sm3, "r", function (origin, stanza) return handle_r(origin, stanza, xmlns_sm3); end); | 214 module:hook_stanza(xmlns_sm3, "r", function (origin, stanza) return handle_r(origin, stanza, xmlns_sm3); end); |
| 215 | 215 |
| 216 function handle_a(origin, stanza) | 216 function handle_a(origin, stanza) |
| 217 if not origin.smacks then return; end | 217 if not origin.smacks then return; end |
| 218 origin.awaiting_ack = nil; | 218 origin.awaiting_ack = nil; |
| 219 if origin.awaiting_ack_timer then | |
| 220 origin.awaiting_ack_timer:stop(); | |
| 221 end | |
| 219 -- Remove handled stanzas from outgoing_stanza_queue | 222 -- Remove handled stanzas from outgoing_stanza_queue |
| 220 --log("debug", "ACK: h=%s, last=%s", stanza.attr.h or "", origin.last_acknowledged_stanza or ""); | 223 --log("debug", "ACK: h=%s, last=%s", stanza.attr.h or "", origin.last_acknowledged_stanza or ""); |
| 221 local h = tonumber(stanza.attr.h); | 224 local h = tonumber(stanza.attr.h); |
| 222 if not h then | 225 if not h then |
| 223 origin:close{ condition = "invalid-xml"; text = "Missing or invalid 'h' attribute"; }; | 226 origin:close{ condition = "invalid-xml"; text = "Missing or invalid 'h' attribute"; }; |
| 394 | 397 |
| 395 local function handle_read_timeout(event) | 398 local function handle_read_timeout(event) |
| 396 local session = event.session; | 399 local session = event.session; |
| 397 if session.smacks then | 400 if session.smacks then |
| 398 if session.awaiting_ack then | 401 if session.awaiting_ack then |
| 402 if session.awaiting_ack_timer then | |
| 403 session.awaiting_ack_timer:stop(); | |
| 404 end | |
| 399 return false; -- Kick the session | 405 return false; -- Kick the session |
| 400 end | 406 end |
| 401 (session.sends2s or session.send)(st.stanza("r", { xmlns = session.smacks })); | 407 (session.sends2s or session.send)(st.stanza("r", { xmlns = session.smacks })); |
| 402 session.awaiting_ack = true; | 408 session.awaiting_ack = true; |
| 403 return true; | 409 return true; |
