Software /
code /
prosody
Comparison
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 |
comparison
equal
deleted
inserted
replaced
4676:1ce2ff9ec313 | 4677:05d8b4099cf5 |
---|---|
124 function deactivate(service_name) | 124 function deactivate(service_name) |
125 local active = active_services:search(service_name)[1]; | 125 local active = active_services:search(service_name)[1]; |
126 if not active then return; end | 126 if not active then return; end |
127 for interface, ports in pairs(active) do | 127 for interface, ports in pairs(active) do |
128 for port, active_service in pairs(ports) do | 128 for port, active_service in pairs(ports) do |
129 active_service:close(); | 129 close(interface, port); |
130 active_services:remove(service_name, interface, port, active_service); | |
131 log("debug", "Removed listening service %s from [%s]:%d", service_name, interface, port); | |
132 end | 130 end |
133 end | 131 end |
134 log("info", "Deactivated service '%s'", service_name); | 132 log("info", "Deactivated service '%s'", service_name); |
135 end | 133 end |
136 | 134 |
163 end | 161 end |
164 end | 162 end |
165 fire_event("service-removed", { name = service_name, service = service_info }); | 163 fire_event("service-removed", { name = service_name, service = service_info }); |
166 end | 164 end |
167 | 165 |
166 function close(interface, port) | |
167 local service, server = get_service_at(interface, port); | |
168 if not service then | |
169 return false, "port-not-open"; | |
170 end | |
171 server:close(); | |
172 active_services:remove(service.name, interface, port); | |
173 log("debug", "Removed listening service %s from [%s]:%d", service.name, interface, port); | |
174 return true; | |
175 end | |
176 | |
177 function get_service_at(interface, port) | |
178 local data = active_services:search(nil, interface, port)[1][1]; | |
179 return data.service, data.server; | |
180 end | |
181 | |
168 function get_service(service_name) | 182 function get_service(service_name) |
169 return services[service_name]; | 183 return services[service_name]; |
170 end | 184 end |
171 | 185 |
172 function get_active_services(...) | 186 function get_active_services(...) |