2 -- Copyright (C) 2008-2009 Matthew Wild
3 -- Copyright (C) 2008-2009 Waqas Hussain
5 -- This project is MIT/X11 licensed. Please see the
6 -- COPYING file in the source package for more information.
11 local listeners_dir = (CFG_SOURCEDIR or ".").."/net/";
12 local server = require "net.server";
13 local log = require "util.logger".init("connlisteners");
14 local tostring = tostring;
16 local dofile, pcall, error =
19 module "connlisteners"
23 function register(name, listener)
24 if listeners[name] and listeners[name] ~= listener then
25 log("debug", "Listener %s is already registered, not registering any more", name);
28 listeners[name] = listener;
29 log("debug", "Registered connection listener %s", name);
33 function deregister(name)
34 listeners[name] = nil;
38 local h = listeners[name];
40 local ok, ret = pcall(dofile, listeners_dir..name:gsub("[^%w%-]", "_").."_listener.lua");
42 log("error", "Error while loading listener '%s': %s", tostring(name), tostring(ret));
50 function start(name, udata)
51 local h, err = get(name);
53 error("No such connection module: "..name.. (err and (" ("..err..")") or ""), 0);
56 local interface = (udata and udata.interface) or h.default_interface or "*";
57 local port = (udata and udata.port) or h.default_port or error("Can't start listener "..name.." because no port was specified, and it has no default port", 0);
58 local mode = (udata and udata.mode) or h.default_mode or 1;
59 local ssl = (udata and udata.ssl) or nil;
60 local maxclients = 99999999;
61 local autossl = udata and udata.type == "ssl";
63 return server.addserver(interface, port, h, mode, autossl and ssl or nil);