Software / code / prosody
Comparison
net/connlisteners.lua @ 4322:aff627b1ce95
connlistener, server_select, prosody: Add support for binding to multiple addresses
| author | Florian Zeitz <florob@babelmonkeys.de> |
|---|---|
| date | Wed, 15 Jun 2011 23:44:18 +0200 |
| parent | 4220:05f4db0459b1 |
| child | 4797:e239668aa6d2 |
comparison
equal
deleted
inserted
replaced
| 4321:4dcdba6900f2 | 4322:aff627b1ce95 |
|---|---|
| 10 | 10 |
| 11 local listeners_dir = (CFG_SOURCEDIR or ".").."/net/"; | 11 local listeners_dir = (CFG_SOURCEDIR or ".").."/net/"; |
| 12 local server = require "net.server"; | 12 local server = require "net.server"; |
| 13 local log = require "util.logger".init("connlisteners"); | 13 local log = require "util.logger".init("connlisteners"); |
| 14 local tostring = tostring; | 14 local tostring = tostring; |
| 15 local type = type | |
| 16 local ipairs = ipairs | |
| 15 | 17 |
| 16 local dofile, xpcall, error = | 18 local dofile, xpcall, error = |
| 17 dofile, xpcall, error | 19 dofile, xpcall, error |
| 18 | 20 |
| 19 local debug_traceback = debug.traceback; | 21 local debug_traceback = debug.traceback; |
| 53 local h, err = get(name); | 55 local h, err = get(name); |
| 54 if not h then | 56 if not h then |
| 55 error("No such connection module: "..name.. (err and (" ("..err..")") or ""), 0); | 57 error("No such connection module: "..name.. (err and (" ("..err..")") or ""), 0); |
| 56 end | 58 end |
| 57 | 59 |
| 58 local interface = (udata and udata.interface) or h.default_interface or "*"; | 60 local interfaces = (udata and udata.interface) or h.default_interface or "*"; |
| 61 if type(interfaces) == "string" then interfaces = {interfaces}; end | |
| 59 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); | 62 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); |
| 60 local mode = (udata and udata.mode) or h.default_mode or 1; | 63 local mode = (udata and udata.mode) or h.default_mode or 1; |
| 61 local ssl = (udata and udata.ssl) or nil; | 64 local ssl = (udata and udata.ssl) or nil; |
| 62 local autossl = udata and udata.type == "ssl"; | 65 local autossl = udata and udata.type == "ssl"; |
| 63 | 66 |
| 64 if autossl and not ssl then | 67 if autossl and not ssl then |
| 65 return nil, "no ssl context"; | 68 return nil, "no ssl context"; |
| 66 end | 69 end |
| 67 | 70 |
| 68 return server.addserver(interface, port, h, mode, autossl and ssl or nil); | 71 ok, err = true, {}; |
| 72 for _, interface in ipairs(interfaces) do | |
| 73 local handler | |
| 74 handler, err[interface] = server.addserver(interface, port, h, mode, autossl and ssl or nil); | |
| 75 ok = ok and handler; | |
| 76 end | |
| 77 | |
| 78 return ok, err; | |
| 69 end | 79 end |
| 70 | 80 |
| 71 return _M; | 81 return _M; |