Diff

plugins/mod_c2s.lua @ 5669:9345c161481f

mod_c2s, mod_s2s: Fire an event on read timeouts
author Kim Alvefur <zash@zash.se>
date Tue, 11 Jun 2013 21:36:15 +0200
parent 5668:5a9318ac92f6
child 5748:cef2a1122b43
line wrap: on
line diff
--- a/plugins/mod_c2s.lua	Tue Jun 11 21:18:51 2013 +0200
+++ b/plugins/mod_c2s.lua	Tue Jun 11 21:36:15 2013 +0200
@@ -265,15 +265,23 @@
 function listener.onreadtimeout(conn)
 	local session = sessions[conn];
 	if session then
-		return session.send(' ');
+		return (hosts[session.host] or prosody).events.fire_event("c2s-read-timeout", { session = session });
 	end
 end
 
+local function keepalive(event)
+	return event.session.send(' ');
+end
+
 function listener.associate_session(conn, session)
 	sessions[conn] = session;
 end
 
-function module.add_host() end
+function module.add_host(module)
+	module:hook("c2s-read-timeout", keepalive, -1);
+end
+
+module:hook("c2s-read-timeout", keepalive, -1);
 
 module:hook("server-stopping", function(event)
 	local reason = event.reason;