# HG changeset patch # User Kim Alvefur # Date 1370979375 -7200 # Node ID 9345c161481fbe16150c7468f3942722dab7bb5b # Parent 5a9318ac92f6dcc6582ec6c0db70f6748f77ae84 mod_c2s, mod_s2s: Fire an event on read timeouts diff -r 5a9318ac92f6 -r 9345c161481f plugins/mod_c2s.lua --- 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; diff -r 5a9318ac92f6 -r 9345c161481f plugins/mod_s2s/mod_s2s.lua --- a/plugins/mod_s2s/mod_s2s.lua Tue Jun 11 21:18:51 2013 +0200 +++ b/plugins/mod_s2s/mod_s2s.lua Tue Jun 11 21:36:15 2013 +0200 @@ -135,6 +135,10 @@ return true; end +local function keepalive(event) + return event.session.sends2s(' '); +end + function module.add_host(module) if module:get_option_boolean("disallow_s2s", false) then module:log("warn", "The 'disallow_s2s' config option is deprecated, please see http://prosody.im/doc/s2s#disabling"); @@ -143,6 +147,7 @@ module:hook("route/remote", route_to_existing_session, -1); module:hook("route/remote", route_to_new_session, -10); module:hook("s2s-authenticated", make_authenticated, -1); + module:hook("s2s-read-timeout", keepalive, -1); end -- Stream is authorised, and ready for normal stanzas @@ -628,7 +633,7 @@ function listener.onreadtimeout(conn) local session = sessions[conn]; if session then - return session.sends2s(' '); + return (hosts[session.host] or prosody).events.fire_event("s2s-read-timeout", { session = session }); end end