mod_smacks: Handle the read timeout event (0.10+ only) and send an ack request, close the connection the second time if unanswerd
authorKim Alvefur <zash@zash.se>
Mon, 11 May 2015 15:07:52 +0200
changeset 1737 9abd3dce619a
parent 1736 2f9ee9ed6267
child 1738 d82b03e79d8b
mod_smacks: Handle the read timeout event (0.10+ only) and send an ack request, close the connection the second time if unanswerd
mod_smacks/mod_smacks.lua
--- a/mod_smacks/mod_smacks.lua	Mon May 11 14:33:37 2015 +0200
+++ b/mod_smacks/mod_smacks.lua	Mon May 11 15:07:52 2015 +0200
@@ -377,3 +377,18 @@
 end
 module:hook_stanza(xmlns_sm2, "resume", function (session, stanza) return handle_resume(session, stanza, xmlns_sm2); end);
 module:hook_stanza(xmlns_sm3, "resume", function (session, stanza) return handle_resume(session, stanza, xmlns_sm3); end);
+
+local function handle_read_timeout(event)
+	local session = event.session;
+	if session.smacks then
+		if session.awaiting_ack then
+			return false; -- Kick the session
+		end
+		(session.sends2s or session.send)(st.stanza("r", { xmlns = session.smacks }));
+		session.awaiting_ack = true;
+		return true;
+	end
+end
+
+module:hook("s2s-read-timeout", handle_read_timeout);
+module:hook("c2s-read-timeout", handle_read_timeout);