2 -- Copyright (C) 2008 Matthew Wild
3 -- Copyright (C) 2008 Waqas Hussain
5 -- This program is free software; you can redistribute it and/or
6 -- modify it under the terms of the GNU General Public License
7 -- as published by the Free Software Foundation; either version 2
8 -- of the License, or (at your option) any later version.
10 -- This program is distributed in the hope that it will be useful,
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 -- GNU General Public License for more details.
15 -- You should have received a copy of the GNU General Public License
16 -- along with this program; if not, write to the Free Software
17 -- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 local listeners_dir = (CFG_SOURCEDIR or ".").."/net/";
23 local server_add = require "net.server".add;
24 local log = require "util.logger".init("connlisteners");
26 local dofile, pcall, error =
29 module "connlisteners"
33 function register(name, listener)
34 if listeners[name] and listeners[name] ~= listener then
35 log("warning", "Listener %s is already registered, not registering any more", name);
38 listeners[name] = listener;
39 log("info", "Registered connection listener %s", name);
43 function deregister(name)
44 listeners[name] = nil;
48 local h = listeners[name];
50 local ok, ret = pcall(dofile, listeners_dir..name:gsub("[^%w%-]", "_").."_listener.lua");
51 if not ok then return nil, ret; end
57 function start(name, udata)
60 error("No such connection module: "..name, 0);
63 (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),
64 (udata and udata.interface) or "*", (udata and udata.mode) or h.default_mode or 1, (udata and udata.ssl) or nil );