Mercurial > prosody-hg
comparison plugins/mod_component.lua @ 7886:679746cdf3cc
mod_component: Add read timeout handler (same behaviour as c2s and s2s)
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Fri, 10 Feb 2017 21:25:12 +0100 |
| parents | 8d1ebb9a9b44 |
| children | 93fd15b5ec1b b87e281a7d59 |
comparison
equal
deleted
inserted
replaced
| 7884:60d3b53a36f7 | 7886:679746cdf3cc |
|---|---|
| 26 local log = module._log; | 26 local log = module._log; |
| 27 | 27 |
| 28 local opt_keepalives = module:get_option_boolean("component_tcp_keepalives", module:get_option_boolean("tcp_keepalives", true)); | 28 local opt_keepalives = module:get_option_boolean("component_tcp_keepalives", module:get_option_boolean("tcp_keepalives", true)); |
| 29 | 29 |
| 30 local sessions = module:shared("sessions"); | 30 local sessions = module:shared("sessions"); |
| 31 | |
| 32 local function keepalive(event) | |
| 33 local session = event.session; | |
| 34 if not session.notopen then | |
| 35 return event.session.send(' '); | |
| 36 end | |
| 37 end | |
| 31 | 38 |
| 32 function module.add_host(module) | 39 function module.add_host(module) |
| 33 if module:get_host_type() ~= "component" then | 40 if module:get_host_type() ~= "component" then |
| 34 error("Don't load mod_component manually, it should be for a component, please see http://prosody.im/doc/components", 0); | 41 error("Don't load mod_component manually, it should be for a component, please see http://prosody.im/doc/components", 0); |
| 35 end | 42 end |
| 133 module:hook("message/full", handle_stanza, -1); | 140 module:hook("message/full", handle_stanza, -1); |
| 134 module:hook("presence/full", handle_stanza, -1); | 141 module:hook("presence/full", handle_stanza, -1); |
| 135 module:hook("iq/host", handle_stanza, -1); | 142 module:hook("iq/host", handle_stanza, -1); |
| 136 module:hook("message/host", handle_stanza, -1); | 143 module:hook("message/host", handle_stanza, -1); |
| 137 module:hook("presence/host", handle_stanza, -1); | 144 module:hook("presence/host", handle_stanza, -1); |
| 138 end | 145 |
| 146 module:hook("component-read-timeout", keepalive, -1); | |
| 147 end | |
| 148 | |
| 149 module:hook("component-read-timeout", keepalive, -1); | |
| 139 | 150 |
| 140 --- Network and stream part --- | 151 --- Network and stream part --- |
| 141 | 152 |
| 142 local xmlns_component = 'jabber:component:accept'; | 153 local xmlns_component = 'jabber:component:accept'; |
| 143 | 154 |
| 330 | 341 |
| 331 function listener.ondetach(conn) | 342 function listener.ondetach(conn) |
| 332 sessions[conn] = nil; | 343 sessions[conn] = nil; |
| 333 end | 344 end |
| 334 | 345 |
| 346 function listener.onreadtimeout(conn) | |
| 347 local session = sessions[conn]; | |
| 348 if session then | |
| 349 return (hosts[session.host] or prosody).events.fire_event("component-read-timeout", { session = session }); | |
| 350 end | |
| 351 end | |
| 352 | |
| 335 module:provides("net", { | 353 module:provides("net", { |
| 336 name = "component"; | 354 name = "component"; |
| 337 private = true; | 355 private = true; |
| 338 listener = listener; | 356 listener = listener; |
| 339 default_port = 5347; | 357 default_port = 5347; |
