Software /
code /
prosody
Changeset
4897:1a90e5225b22
portmanager: Fix to deactivate services when they are unregistered (metatable:iter() wins)
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Sat, 19 May 2012 20:46:44 +0100 |
parents | 4896:27cda15104f2 |
children | 4898:010c01841ed0 |
files | core/portmanager.lua |
diffstat | 1 files changed, 8 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/core/portmanager.lua Sat May 19 15:39:16 2012 +0100 +++ b/core/portmanager.lua Sat May 19 20:46:44 2012 +0100 @@ -134,15 +134,11 @@ return true; end -function deactivate(service_name) - local active = active_services:search(service_name)[1]; - if not active then return; end - for interface, ports in pairs(active) do - for port, active_service in pairs(ports) do - close(interface, port); - end +function deactivate(service_name, service_info) + for name, interface, port, active_service in active_services:iter(service_name, nil, nil, service_info) do + close(interface, port); end - log("info", "Deactivated service '%s'", service_name); + log("info", "Deactivated service '%s'", service_name or service_info.name); end function register_service(service_name, service_info) @@ -161,17 +157,16 @@ end function unregister_service(service_name, service_info) + log("debug", "Unregistering service: %s", service_name); local service_info_list = services[service_name]; for i, service in ipairs(service_info_list) do if service == service_info then table.remove(service_info_list, i); end end - if active_services[service_name] == service_info then - deactivate(service_name); - if #service_info_list > 0 then -- Other services registered with this name - activate(service_name); -- Re-activate with the next available one - end + deactivate(nil, service_info); + if #service_info_list > 0 then -- Other services registered with this name + activate(service_name); -- Re-activate with the next available one end fire_event("service-removed", { name = service_name, service = service_info }); end