aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2023-05-20 20:44:20 +0200
committerKim Alvefur <zash@zash.se>2023-05-20 20:44:20 +0200
commitc468bd12c9a8e9ed5123128a67bbdb44c555f6f7 (patch)
treee5bdceb28546719d5e03180e545d40731715de6c
parentaf2cf5f188a2bf62da97453f0d21e282f7f67985 (diff)
downloadprosody-c468bd12c9a8e9ed5123128a67bbdb44c555f6f7.tar.gz
prosody-c468bd12c9a8e9ed5123128a67bbdb44c555f6f7.zip
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.
-rw-r--r--net/server.lua35
1 files changed, 20 insertions, 15 deletions
diff --git a/net/server.lua b/net/server.lua
index 1240c98d..942aceb2 100644
--- a/net/server.lua
+++ b/net/server.lua
@@ -6,20 +6,23 @@
-- 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";
+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;
-local server_type = require "prosody.core.configmanager".get("*", "network_backend") or default_backend;
-
-if require "prosody.core.configmanager".get("*", "use_libevent") then
- server_type = "event";
+ 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
@@ -118,11 +121,13 @@ if prosody and set_config then
prosody.events.add_handler("config-reloaded", load_config);
end
-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 "")
+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,