Software /
code /
prosody
Diff
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 |
line wrap: on
line diff
--- a/net/connlisteners.lua Sun Jun 12 22:21:10 2011 +0100 +++ b/net/connlisteners.lua Wed Jun 15 23:44:18 2011 +0200 @@ -12,6 +12,8 @@ local server = require "net.server"; local log = require "util.logger".init("connlisteners"); local tostring = tostring; +local type = type +local ipairs = ipairs local dofile, xpcall, error = dofile, xpcall, error @@ -55,7 +57,8 @@ error("No such connection module: "..name.. (err and (" ("..err..")") or ""), 0); end - local interface = (udata and udata.interface) or h.default_interface or "*"; + local interfaces = (udata and udata.interface) or h.default_interface or "*"; + if type(interfaces) == "string" then interfaces = {interfaces}; end 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); local mode = (udata and udata.mode) or h.default_mode or 1; local ssl = (udata and udata.ssl) or nil; @@ -64,8 +67,15 @@ if autossl and not ssl then return nil, "no ssl context"; end - - return server.addserver(interface, port, h, mode, autossl and ssl or nil); + + ok, err = true, {}; + for _, interface in ipairs(interfaces) do + local handler + handler, err[interface] = server.addserver(interface, port, h, mode, autossl and ssl or nil); + ok = ok and handler; + end + + return ok, err; end return _M;