Changeset

6380:4220ffb87b22

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)
author Matthew Wild <mwild1@gmail.com>
date Fri, 29 Aug 2014 11:54:34 +0100
parents 6379:a280bd6ccce2
children 6381:9ffd582c65d8
files net/http.lua net/http/server.lua plugins/mod_admin_telnet.lua plugins/mod_c2s.lua plugins/mod_component.lua plugins/mod_net_multiplex.lua plugins/mod_s2s/mod_s2s.lua
diffstat 7 files changed, 26 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- 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)
--- 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
--- 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
 
--- 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
--- 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;
--- 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 = "";
--- 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;