comparison mod_register_json/mod_register_json.lua @ 561:f2ec7149b005

mod_register_json: reworked the ccleanup function so that it doesn' try to close an unused listener port if server_event is in use (works only with select)
author Marco Cirillo <maranda@lightwitch.org>
date Tue, 17 Jan 2012 01:18:36 +0000
parents b62f5e38f865
children cd5581b58fdc
comparison
equal deleted inserted replaced
560:b62f5e38f865 561:f2ec7149b005
122 if options.port then 122 if options.port then
123 httpserver.new.http_servers[options.port].handlers[options.path or "register_account"] = nil 123 httpserver.new.http_servers[options.port].handlers[options.path or "register_account"] = nil
124 end 124 end
125 end 125 end
126 126
127 -- if there're no handlers left clean the socket, not sure if it works with server_select 127 -- if there are no handlers left clean and close the socket, doesn't work with server_event
128 for _, options in ipairs(ports) do 128 local event = module:get_option_boolean("use_libevent", nil)
129 if options.port and not next(httpserver.new.http_servers[options.port].handlers) then 129
130 httpserver.new.http_servers[options.port] = nil 130 if not event then
131 if options.interface then 131 for _, options in ipairs(ports) do
132 for _, value in ipairs(options.interface) do 132 if options.port and not next(httpserver.new.http_servers[options.port].handlers) then
133 if server.getserver(value, options.port) then server.removeserver(value, options.port) end 133 httpserver.new.http_servers[options.port] = nil
134 end 134 if options.interface then
135 else if server.getserver("*", options.port) then server.removeserver("*", options.port) end end 135 for _, value in ipairs(options.interface) do
136 if server.getserver(value, options.port) then server.removeserver(value, options.port) end
137 end
138 else if server.getserver("*", options.port) then server.removeserver("*", options.port) end end
139 end
136 end 140 end
137 end 141 end
138 142
139 prosody.events.remove_handler("module-unloaded", cleanup) 143 prosody.events.remove_handler("module-unloaded", cleanup)
140 end 144 end