Comparison

net/connlisteners.lua @ 99:ba08b8a4eeef

Abstract connections with "connection listeners" - Added connlistener for xmppclient - SASL/TLS now use a new session:reset_stream() method - main.lua on its way to being a bit neater
author Matthew Wild <mwild1@gmail.com>
date Wed, 22 Oct 2008 17:36:21 +0100
child 127:93f3c6b94c75
comparison
equal deleted inserted replaced
98:3a2d327c4856 99:ba08b8a4eeef
1
2 local server_add = require "net.server".add;
3 local log = require "util.logger".init("connlisteners");
4
5 local dofile, pcall, error =
6 dofile, pcall, error
7
8 module "connlisteners"
9
10 local listeners = {};
11
12 function register(name, listener)
13 if listeners[name] and listeners[name] ~= listener then
14 log("warning", "Listener %s is already registered, not registering any more", name);
15 return false;
16 end
17 listeners[name] = listener;
18 log("info", "Registered connection listener %s", name);
19 return true;
20 end
21
22 function deregister(name)
23 listeners[name] = nil;
24 end
25
26 function start(name, udata)
27 local h = listeners[name]
28 if not h then
29 pcall(dofile, "net/"..name:gsub("[^%w%-]", "_").."_listener.lua");
30 h = listeners[name];
31 if not h then
32 error("No such connection module: "..name, 0);
33 end
34 end
35 return server_add(h,
36 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),
37 udata.interface or "*", udata.mode or h.default_mode or 1, udata.ssl );
38 end
39
40 return _M;