Software /
code /
prosody
Changeset
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 |
parents | 5668:5a9318ac92f6 |
children | 5674:ebdbf4cf0b2f |
files | plugins/mod_c2s.lua plugins/mod_s2s/mod_s2s.lua |
diffstat | 2 files changed, 16 insertions(+), 3 deletions(-) [+] |
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;
--- 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