Mercurial > prosody-modules
comparison mod_smacks/mod_smacks.lua @ 622:ce39df945de1
mod_smacks: Use pre-resource-unbind (0.9 feature) to fix reloadability and multiple host support
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Mon, 05 Mar 2012 16:53:30 +0000 |
| parents | 7693724881b3 |
| children | c1f3958695ea |
comparison
equal
deleted
inserted
replaced
| 621:7bdd02056e2b | 622:ce39df945de1 |
|---|---|
| 196 end | 196 end |
| 197 end | 197 end |
| 198 end | 198 end |
| 199 end | 199 end |
| 200 | 200 |
| 201 local _destroy_session = sessionmanager.destroy_session; | 201 module:hook("pre-resource-unbind", function (event) |
| 202 function sessionmanager.destroy_session(session, err) | 202 local session, err = event.session, event.error; |
| 203 if session.smacks then | 203 if session.smacks then |
| 204 if not session.resumption_token then | 204 if not session.resumption_token then |
| 205 local queue = session.outgoing_stanza_queue; | 205 local queue = session.outgoing_stanza_queue; |
| 206 if #queue > 0 then | 206 if #queue > 0 then |
| 207 module:log("warn", "Destroying session with %d unacked stanzas:", #queue); | 207 module:log("warn", "Destroying session with %d unacked stanzas:", #queue); |
| 227 -- otherwise the session resumed and re-hibernated. | 227 -- otherwise the session resumed and re-hibernated. |
| 228 and session.hibernating == hibernate_time then | 228 and session.hibernating == hibernate_time then |
| 229 session.log("debug", "Destroying session for hibernating too long"); | 229 session.log("debug", "Destroying session for hibernating too long"); |
| 230 session_registry[session.resumption_token] = nil; | 230 session_registry[session.resumption_token] = nil; |
| 231 session.resumption_token = nil; | 231 session.resumption_token = nil; |
| 232 -- This recursion back into our destroy handler is to | |
| 233 -- make sure we still handle any queued stanzas | |
| 234 sessionmanager.destroy_session(session); | 232 sessionmanager.destroy_session(session); |
| 235 else | 233 else |
| 236 session.log("debug", "Session resumed before hibernation timeout, all is well") | 234 session.log("debug", "Session resumed before hibernation timeout, all is well") |
| 237 end | 235 end |
| 238 end); | 236 end); |
| 239 return; -- Postpone destruction for now | 237 return true; -- Postpone destruction for now |
| 240 end | 238 end |
| 241 | 239 |
| 242 end | 240 end |
| 243 return _destroy_session(session, err); | 241 end); |
| 244 end | |
| 245 | 242 |
| 246 module:hook_stanza(xmlns_sm, "resume", function (session, stanza) | 243 module:hook_stanza(xmlns_sm, "resume", function (session, stanza) |
| 247 local id = stanza.attr.previd; | 244 local id = stanza.attr.previd; |
| 248 local original_session = session_registry[id]; | 245 local original_session = session_registry[id]; |
| 249 if not original_session then | 246 if not original_session then |
