diff options
author | Matthew Wild <mwild1@gmail.com> | 2012-04-24 16:00:20 +0100 |
---|---|---|
committer | Matthew Wild <mwild1@gmail.com> | 2012-04-24 16:00:20 +0100 |
commit | 64d127307adc8aa401d7ae4a964298cae4d08016 (patch) | |
tree | 03f788bb583cfd6faecb60f182defc218510637b | |
parent | 824fdebc5566bae7fe69811bff0d1b4517a78925 (diff) | |
download | prosody-64d127307adc8aa401d7ae4a964298cae4d08016.tar.gz prosody-64d127307adc8aa401d7ae4a964298cae4d08016.zip |
portmanager: Add get_service_at(interface, port) and close(interface, port)
-rw-r--r-- | core/portmanager.lua | 20 |
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 |