Software /
code /
prosody
Comparison
net/server.lua @ 12974:ba409c67353b
net: Prefix module imports with prosody namespace
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Fri, 17 Mar 2023 16:23:12 +0100 |
parent | 12481:2ee27587fec7 |
child | 13166:e6e76f64ebb6 |
comparison
equal
deleted
inserted
replaced
12973:cc215923297f | 12974:ba409c67353b |
---|---|
10 -- This module only supports loading inside Prosody, outside Prosody | 10 -- This module only supports loading inside Prosody, outside Prosody |
11 -- you should directly require net.server_select or server_event, etc. | 11 -- you should directly require net.server_select or server_event, etc. |
12 error(debug.traceback("Loading outside Prosody or Prosody not yet initialized"), 0); | 12 error(debug.traceback("Loading outside Prosody or Prosody not yet initialized"), 0); |
13 end | 13 end |
14 | 14 |
15 local log = require "util.logger".init("net.server"); | 15 local log = require "prosody.util.logger".init("net.server"); |
16 | 16 |
17 local default_backend = "epoll"; | 17 local default_backend = "epoll"; |
18 | 18 |
19 local server_type = require "core.configmanager".get("*", "network_backend") or default_backend; | 19 local server_type = require "prosody.core.configmanager".get("*", "network_backend") or default_backend; |
20 | 20 |
21 if require "core.configmanager".get("*", "use_libevent") then | 21 if require "prosody.core.configmanager".get("*", "use_libevent") then |
22 server_type = "event"; | 22 server_type = "event"; |
23 end | 23 end |
24 | 24 |
25 if server_type == "event" then | 25 if server_type == "event" then |
26 if not pcall(require, "luaevent.core") then | 26 if not pcall(require, "luaevent.core") then |
30 end | 30 end |
31 | 31 |
32 local server; | 32 local server; |
33 local set_config; | 33 local set_config; |
34 if server_type == "event" then | 34 if server_type == "event" then |
35 server = require "net.server_event"; | 35 server = require "prosody.net.server_event"; |
36 | 36 |
37 local defaults = {}; | 37 local defaults = {}; |
38 for k,v in pairs(server.cfg) do | 38 for k,v in pairs(server.cfg) do |
39 defaults[k] = v; | 39 defaults[k] = v; |
40 end | 40 end |
59 end | 59 end |
60 end | 60 end |
61 elseif server_type == "select" then | 61 elseif server_type == "select" then |
62 -- TODO Remove completely. | 62 -- TODO Remove completely. |
63 log("warn", "select is deprecated, the new default is epoll. For more info see https://prosody.im/doc/network_backend"); | 63 log("warn", "select is deprecated, the new default is epoll. For more info see https://prosody.im/doc/network_backend"); |
64 server = require "net.server_select"; | 64 server = require "prosody.net.server_select"; |
65 | 65 |
66 local defaults = {}; | 66 local defaults = {}; |
67 for k,v in pairs(server.getsettings()) do | 67 for k,v in pairs(server.getsettings()) do |
68 defaults[k] = v; | 68 defaults[k] = v; |
69 end | 69 end |
73 select_settings[k] = settings[k] or default; | 73 select_settings[k] = settings[k] or default; |
74 end | 74 end |
75 server.changesettings(select_settings); | 75 server.changesettings(select_settings); |
76 end | 76 end |
77 else | 77 else |
78 server = require("net.server_"..server_type); | 78 server = require("prosody.net.server_"..server_type); |
79 set_config = server.set_config; | 79 set_config = server.set_config; |
80 if not server.get_backend then | 80 if not server.get_backend then |
81 function server.get_backend() | 81 function server.get_backend() |
82 return server_type; | 82 return server_type; |
83 end | 83 end |
84 end | 84 end |
85 end | 85 end |
86 | 86 |
87 -- If server.hook_signal exists, replace signal.signal() | 87 -- If server.hook_signal exists, replace signal.signal() |
88 local has_signal, signal = pcall(require, "util.signal"); | 88 local has_signal, signal = pcall(require, "prosody.util.signal"); |
89 if has_signal then | 89 if has_signal then |
90 if server.hook_signal then | 90 if server.hook_signal then |
91 function signal.signal(signal_id, handler) | 91 function signal.signal(signal_id, handler) |
92 if type(signal_id) == "string" then | 92 if type(signal_id) == "string" then |
93 signal_id = signal[signal_id:upper()]; | 93 signal_id = signal[signal_id:upper()]; |
107 end | 107 end |
108 end | 108 end |
109 end | 109 end |
110 | 110 |
111 if prosody and set_config then | 111 if prosody and set_config then |
112 local config_get = require "core.configmanager".get; | 112 local config_get = require "prosody.core.configmanager".get; |
113 local function load_config() | 113 local function load_config() |
114 local settings = config_get("*", "network_settings") or {}; | 114 local settings = config_get("*", "network_settings") or {}; |
115 return set_config(settings); | 115 return set_config(settings); |
116 end | 116 end |
117 load_config(); | 117 load_config(); |
123 -- prosody.paths.config | 123 -- prosody.paths.config |
124 function server.tls_builder() | 124 function server.tls_builder() |
125 return tls_builder(prosody.paths.config or "") | 125 return tls_builder(prosody.paths.config or "") |
126 end | 126 end |
127 | 127 |
128 -- require "net.server" shall now forever return this, | 128 -- require "prosody.net.server" shall now forever return this, |
129 -- ie. server_select or server_event as chosen above. | 129 -- ie. server_select or server_event as chosen above. |
130 return server; | 130 return server; |