Diff

core/portmanager.lua @ 4677:05d8b4099cf5

portmanager: Add get_service_at(interface, port) and close(interface, port)
author Matthew Wild <mwild1@gmail.com>
date Tue, 24 Apr 2012 16:00:20 +0100
parent 4624:3e4715d44561
child 4687:bd3a852b949a
line wrap: on
line diff
--- a/core/portmanager.lua	Tue Apr 24 15:52:30 2012 +0100
+++ b/core/portmanager.lua	Tue Apr 24 16:00:20 2012 +0100
@@ -126,9 +126,7 @@
 	if not active then return; end
 	for interface, ports in pairs(active) do
 		for port, active_service in pairs(ports) do
-			active_service:close();
-			active_services:remove(service_name, interface, port, active_service);
-			log("debug", "Removed listening service %s from [%s]:%d", service_name, interface, port);
+			close(interface, port);
 		end
 	end
 	log("info", "Deactivated service '%s'", service_name);
@@ -165,6 +163,22 @@
 	fire_event("service-removed", { name = service_name, service = service_info });
 end
 
+function close(interface, port)
+	local service, server = get_service_at(interface, port);
+	if not service then
+		return false, "port-not-open";
+	end
+	server:close();
+	active_services:remove(service.name, interface, port);
+	log("debug", "Removed listening service %s from [%s]:%d", service.name, interface, port);
+	return true;
+end
+
+function get_service_at(interface, port)
+	local data = active_services:search(nil, interface, port)[1][1];
+	return data.service, data.server;
+end
+
 function get_service(service_name)
 	return services[service_name];
 end