Comparison

net/server.lua @ 6482:410067cdeb2f

net/server: If server.hook_signal exists, overwrite signal.signal; else make server.hook_signal == signal.signal No longer server_event specific server.hook_signal will always exist
author daurnimator <quae@daurnimator.com>
date Tue, 21 Oct 2014 17:26:48 -0400
parent 6480:37b12475f648
child 6483:63539dfb96e7
comparison
equal deleted inserted replaced
6481:dbc72cd1332e 6482:410067cdeb2f
21 21
22 local server; 22 local server;
23 local set_config; 23 local set_config;
24 if server_type == "event" then 24 if server_type == "event" then
25 server = require "net.server_event"; 25 server = require "net.server_event";
26
27 -- Overwrite signal.signal() because we need to ask libevent to
28 -- handle them instead
29 local ok, signal = pcall(require, "util.signal");
30 if ok and signal then
31 local _signal_signal = signal.signal;
32 function signal.signal(signal_id, handler)
33 if type(signal_id) == "string" then
34 signal_id = signal[signal_id:upper()];
35 end
36 if type(signal_id) ~= "number" then
37 return false, "invalid-signal";
38 end
39 return server.hook_signal(signal_id, handler);
40 end
41 end
42 26
43 local defaults = {}; 27 local defaults = {};
44 for k,v in pairs(server.cfg) do 28 for k,v in pairs(server.cfg) do
45 defaults[k] = v; 29 defaults[k] = v;
46 end 30 end
80 end 64 end
81 else 65 else
82 error("Unsupported server type") 66 error("Unsupported server type")
83 end 67 end
84 68
69 -- If server.hook_signal exists, replace signal.signal()
70 local ok, signal = pcall(require, "util.signal");
71 if server.hook_signal then
72 if ok then
73 function signal.signal(signal_id, handler)
74 if type(signal_id) == "string" then
75 signal_id = signal[signal_id:upper()];
76 end
77 if type(signal_id) ~= "number" then
78 return false, "invalid-signal";
79 end
80 return server.hook_signal(signal_id, handler);
81 end
82 end
83 else
84 server.hook_signal = signal.signal;
85 end
86
85 if prosody then 87 if prosody then
86 local config_get = require "core.configmanager".get; 88 local config_get = require "core.configmanager".get;
87 local function load_config() 89 local function load_config()
88 local settings = config_get("*", "network_settings") or {}; 90 local settings = config_get("*", "network_settings") or {};
89 return set_config(settings); 91 return set_config(settings);