net.server: Handle loading from outside Prosody (e.g. Verse)

server_select only depending on LuaSocket generally makes it more
portable, so fall back to that if util.poll can't be found.
This commit is contained in:
Kim Alvefur 2023-05-20 20:44:20 +02:00
parent af2cf5f188
commit c468bd12c9

View file

@ -6,21 +6,24 @@
-- COPYING file in the source package for more information.
--
if not (prosody and prosody.config_loaded) then
-- This module only supports loading inside Prosody, outside Prosody
-- you should directly require net.server_select or server_event, etc.
error(debug.traceback("Loading outside Prosody or Prosody not yet initialized"), 0);
local function log(level, format, ...)
print("net.server", level, format:format(...));
end
local log = require "prosody.util.logger".init("net.server");
local default_backend = "select";
local server_type = default_backend;
local default_backend = "epoll";
local server_type = require "prosody.core.configmanager".get("*", "network_backend") or default_backend;
if (prosody and prosody.config_loaded) then
default_backend = "epoll";
log = require"prosody.util.logger".init("net.server");
server_type = require"prosody.core.configmanager".get("*", "network_backend") or default_backend;
if require"prosody.core.configmanager".get("*", "use_libevent") then
server_type = "event";
end
elseif pcall(require, "prosody.util.poll") then
server_type = "epoll";
end
if server_type == "event" then
if not pcall(require, "luaevent.core") then
@ -118,12 +121,14 @@ if prosody and set_config then
prosody.events.add_handler("config-reloaded", load_config);
end
if prosody and server.tls_builder then
local tls_builder = server.tls_builder;
-- resolving the basedir here avoids util.sslconfig depending on
-- prosody.paths.config
function server.tls_builder()
return tls_builder(prosody.paths.config or "")
end
end
-- require "prosody.net.server" shall now forever return this,
-- ie. server_select or server_event as chosen above.