aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2012-04-24 16:00:20 +0100
committerMatthew Wild <mwild1@gmail.com>2012-04-24 16:00:20 +0100
commit1dea1062ea7a5a446bd72b82bab5ce373294e9d8 (patch)
tree03f788bb583cfd6faecb60f182defc218510637b /core
parentdcdfe0e0ceb454cbb8ecb8461fd4648f5e560830 (diff)
downloadprosody-1dea1062ea7a5a446bd72b82bab5ce373294e9d8.tar.gz
prosody-1dea1062ea7a5a446bd72b82bab5ce373294e9d8.zip
portmanager: Add get_service_at(interface, port) and close(interface, port)
Diffstat (limited to 'core')
-rw-r--r--core/portmanager.lua20
1 files changed, 17 insertions, 3 deletions
diff --git a/core/portmanager.lua b/core/portmanager.lua
index c5bb936a..da238dba 100644
--- a/core/portmanager.lua
+++ b/core/portmanager.lua
@@ -126,9 +126,7 @@ function deactivate(service_name)
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 @@ function unregister_service(service_name, service_info)
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