Software /
code /
prosody
Comparison
core/portmanager.lua @ 6788:d64c1f3c7e2e
portmanager: Add forward declarations
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Wed, 08 Apr 2015 00:45:26 +0200 |
parent | 6779:6236668da30a |
child | 6980:daaa52b3f45f |
comparison
equal
deleted
inserted
replaced
6787:ad64e2eacd0e | 6788:d64c1f3c7e2e |
---|---|
140 end | 140 end |
141 log("info", "Activated service '%s' on %s", service_name, #hooked_ports == 0 and "no ports" or table.concat(hooked_ports, ", ")); | 141 log("info", "Activated service '%s' on %s", service_name, #hooked_ports == 0 and "no ports" or table.concat(hooked_ports, ", ")); |
142 return true; | 142 return true; |
143 end | 143 end |
144 | 144 |
145 local close; -- forward declaration | |
146 | |
145 local function deactivate(service_name, service_info) | 147 local function deactivate(service_name, service_info) |
146 for name, interface, port, n, active_service --luacheck: ignore 213/name 213/n | 148 for name, interface, port, n, active_service --luacheck: ignore 213/name 213/n |
147 in active_services:iter(service_name or service_info and service_info.name, nil, nil, nil) do | 149 in active_services:iter(service_name or service_info and service_info.name, nil, nil, nil) do |
148 if service_info == nil or active_service.service == service_info then | 150 if service_info == nil or active_service.service == service_info then |
149 close(interface, port); | 151 close(interface, port); |
180 activate(service_name); -- Re-activate with the next available one | 182 activate(service_name); -- Re-activate with the next available one |
181 end | 183 end |
182 fire_event("service-removed", { name = service_name, service = service_info }); | 184 fire_event("service-removed", { name = service_name, service = service_info }); |
183 end | 185 end |
184 | 186 |
185 local function close(interface, port) | 187 local get_service_at -- forward declaration |
188 | |
189 function close(interface, port) | |
186 local service, service_server = get_service_at(interface, port); | 190 local service, service_server = get_service_at(interface, port); |
187 if not service then | 191 if not service then |
188 return false, "port-not-open"; | 192 return false, "port-not-open"; |
189 end | 193 end |
190 service_server:close(); | 194 service_server:close(); |
191 active_services:remove(service.name, interface, port); | 195 active_services:remove(service.name, interface, port); |
192 log("debug", "Removed listening service %s from [%s]:%d", service.name, interface, port); | 196 log("debug", "Removed listening service %s from [%s]:%d", service.name, interface, port); |
193 return true; | 197 return true; |
194 end | 198 end |
195 | 199 |
196 local function get_service_at(interface, port) | 200 function get_service_at(interface, port) |
197 local data = active_services:search(nil, interface, port)[1][1]; | 201 local data = active_services:search(nil, interface, port)[1][1]; |
198 return data.service, data.server; | 202 return data.service, data.server; |
199 end | 203 end |
200 | 204 |
201 local function get_service(service_name) | 205 local function get_service(service_name) |