# HG changeset patch # User Matthew Wild # Date 1409309674 -3600 # Node ID 4220ffb87b224b6d3986c5430db89afc17fc8767 # Parent a280bd6ccce29fff602c257f255be966d78da611 net.http, net.http.server, mod_c2s, mod_s2s, mod_component, mod_admin_telnet, mod_net_multiplex: Add ondetach to release connection from 'sessions' table (or equivalent) diff -r a280bd6ccce2 -r 4220ffb87b22 net/http.lua --- a/net/http.lua Fri Aug 29 11:39:56 2014 +0100 +++ b/net/http.lua Fri Aug 29 11:54:34 2014 +0100 @@ -72,6 +72,10 @@ requests[conn] = nil; end +function listener.ondetach(conn) + requests[conn] = nil; +end + local function request_reader(request, data, err) if not request.parser then local function error_cb(reason) diff -r a280bd6ccce2 -r 4220ffb87b22 net/http/server.lua --- a/net/http/server.lua Fri Aug 29 11:39:56 2014 +0100 +++ b/net/http/server.lua Fri Aug 29 11:54:34 2014 +0100 @@ -142,6 +142,10 @@ sessions[conn] = nil; end +function listener.ondetach(conn) + sessions[conn] = nil; +end + function listener.onincoming(conn, data) sessions[conn]:feed(data); end diff -r a280bd6ccce2 -r 4220ffb87b22 plugins/mod_admin_telnet.lua --- a/plugins/mod_admin_telnet.lua Fri Aug 29 11:39:56 2014 +0100 +++ b/plugins/mod_admin_telnet.lua Fri Aug 29 11:54:34 2014 +0100 @@ -163,6 +163,10 @@ end end +function console_listener.ondetach(conn) + sessions[conn] = nil; +end + -- Console commands -- -- These are simple commands, not valid standalone in Lua diff -r a280bd6ccce2 -r 4220ffb87b22 plugins/mod_c2s.lua --- a/plugins/mod_c2s.lua Fri Aug 29 11:39:56 2014 +0100 +++ b/plugins/mod_c2s.lua Fri Aug 29 11:54:34 2014 +0100 @@ -266,6 +266,10 @@ sessions[conn] = session; end +function listener.ondetach(conn) + sessions[conn] = nil; +end + module:hook("server-stopping", function(event) local reason = event.reason; for _, session in pairs(sessions) do diff -r a280bd6ccce2 -r 4220ffb87b22 plugins/mod_component.lua --- a/plugins/mod_component.lua Fri Aug 29 11:39:56 2014 +0100 +++ b/plugins/mod_component.lua Fri Aug 29 11:54:34 2014 +0100 @@ -319,6 +319,10 @@ end end +function listener.ondetach(conn) + sessions[conn] = nil; +end + module:provides("net", { name = "component"; private = true; diff -r a280bd6ccce2 -r 4220ffb87b22 plugins/mod_net_multiplex.lua --- a/plugins/mod_net_multiplex.lua Fri Aug 29 11:39:56 2014 +0100 +++ b/plugins/mod_net_multiplex.lua Fri Aug 29 11:54:34 2014 +0100 @@ -34,7 +34,6 @@ function listener.onincoming(conn, data) if not data then return; end local buf = buffers[conn]; - buffers[conn] = nil; buf = buf and buf..data or data; for service, multiplex_pattern in pairs(available_services) do if buf:match(multiplex_pattern) then @@ -57,6 +56,8 @@ buffers[conn] = nil; -- warn if no buffer? end +listener.ondetach = listener.ondisconnect; + module:provides("net", { name = "multiplex"; config_prefix = ""; diff -r a280bd6ccce2 -r 4220ffb87b22 plugins/mod_s2s/mod_s2s.lua --- a/plugins/mod_s2s/mod_s2s.lua Fri Aug 29 11:39:56 2014 +0100 +++ b/plugins/mod_s2s/mod_s2s.lua Fri Aug 29 11:54:34 2014 +0100 @@ -638,6 +638,10 @@ initialize_session(session); end +function listener.ondetach(conn) + sessions[conn] = nil; +end + function check_auth_policy(event) local host, session = event.host, event.session; local must_secure = secure_auth;