Comparison

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
comparison
equal deleted inserted replaced
5668:5a9318ac92f6 5669:9345c161481f
263 end 263 end
264 264
265 function listener.onreadtimeout(conn) 265 function listener.onreadtimeout(conn)
266 local session = sessions[conn]; 266 local session = sessions[conn];
267 if session then 267 if session then
268 return session.send(' '); 268 return (hosts[session.host] or prosody).events.fire_event("c2s-read-timeout", { session = session });
269 end 269 end
270 end
271
272 local function keepalive(event)
273 return event.session.send(' ');
270 end 274 end
271 275
272 function listener.associate_session(conn, session) 276 function listener.associate_session(conn, session)
273 sessions[conn] = session; 277 sessions[conn] = session;
274 end 278 end
275 279
276 function module.add_host() end 280 function module.add_host(module)
281 module:hook("c2s-read-timeout", keepalive, -1);
282 end
283
284 module:hook("c2s-read-timeout", keepalive, -1);
277 285
278 module:hook("server-stopping", function(event) 286 module:hook("server-stopping", function(event)
279 local reason = event.reason; 287 local reason = event.reason;
280 for _, session in pairs(sessions) do 288 for _, session in pairs(sessions) do
281 session:close{ condition = "system-shutdown", text = reason }; 289 session:close{ condition = "system-shutdown", text = reason };