Mercurial > prosody-hg
comparison net/server.lua @ 13166:e6e76f64ebb6
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.
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Sat, 20 May 2023 20:44:20 +0200 |
| parents | ba409c67353b |
| children | 4a9a69659727 |
comparison
equal
deleted
inserted
replaced
| 13165:9c13c11b199d | 13166:e6e76f64ebb6 |
|---|---|
| 4 -- | 4 -- |
| 5 -- This project is MIT/X11 licensed. Please see the | 5 -- This project is MIT/X11 licensed. Please see the |
| 6 -- COPYING file in the source package for more information. | 6 -- COPYING file in the source package for more information. |
| 7 -- | 7 -- |
| 8 | 8 |
| 9 if not (prosody and prosody.config_loaded) then | 9 local function log(level, format, ...) |
| 10 -- This module only supports loading inside Prosody, outside Prosody | 10 print("net.server", level, format:format(...)); |
| 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); | |
| 13 end | 11 end |
| 14 | 12 |
| 15 local log = require "prosody.util.logger".init("net.server"); | 13 local default_backend = "select"; |
| 14 local server_type = default_backend; | |
| 16 | 15 |
| 17 local default_backend = "epoll"; | 16 if (prosody and prosody.config_loaded) then |
| 17 default_backend = "epoll"; | |
| 18 log = require"prosody.util.logger".init("net.server"); | |
| 19 server_type = require"prosody.core.configmanager".get("*", "network_backend") or default_backend; | |
| 18 | 20 |
| 19 local server_type = require "prosody.core.configmanager".get("*", "network_backend") or default_backend; | 21 if require"prosody.core.configmanager".get("*", "use_libevent") then |
| 20 | 22 server_type = "event"; |
| 21 if require "prosody.core.configmanager".get("*", "use_libevent") then | 23 end |
| 22 server_type = "event"; | 24 elseif pcall(require, "prosody.util.poll") then |
| 25 server_type = "epoll"; | |
| 23 end | 26 end |
| 24 | 27 |
| 25 if server_type == "event" then | 28 if server_type == "event" then |
| 26 if not pcall(require, "luaevent.core") then | 29 if not pcall(require, "luaevent.core") then |
| 27 log("error", "libevent not found, falling back to %s", default_backend); | 30 log("error", "libevent not found, falling back to %s", default_backend); |
| 116 end | 119 end |
| 117 load_config(); | 120 load_config(); |
| 118 prosody.events.add_handler("config-reloaded", load_config); | 121 prosody.events.add_handler("config-reloaded", load_config); |
| 119 end | 122 end |
| 120 | 123 |
| 121 local tls_builder = server.tls_builder; | 124 if prosody and server.tls_builder then |
| 122 -- resolving the basedir here avoids util.sslconfig depending on | 125 local tls_builder = server.tls_builder; |
| 123 -- prosody.paths.config | 126 -- resolving the basedir here avoids util.sslconfig depending on |
| 124 function server.tls_builder() | 127 -- prosody.paths.config |
| 125 return tls_builder(prosody.paths.config or "") | 128 function server.tls_builder() |
| 129 return tls_builder(prosody.paths.config or "") | |
| 130 end | |
| 126 end | 131 end |
| 127 | 132 |
| 128 -- require "prosody.net.server" shall now forever return this, | 133 -- require "prosody.net.server" shall now forever return this, |
| 129 -- ie. server_select or server_event as chosen above. | 134 -- ie. server_select or server_event as chosen above. |
| 130 return server; | 135 return server; |
