fix: cluster 支持ipv6地址字符串 (#2124)

Co-authored-by: zhuyin.zhu <zhuyin.zhu@bytedance.com>
This commit is contained in:
IAN.Z
2025-12-26 12:35:29 +08:00
committed by GitHub
parent a4c6e04ab0
commit 1bbdeb3132
2 changed files with 5 additions and 2 deletions

View File

@@ -408,7 +408,8 @@ end
function socket.listen(host, port, backlog) function socket.listen(host, port, backlog)
if port == nil then if port == nil then
host, port = string.match(host, "([^:]+):(.+)$") host, port = string.match(host, "(.+):([^:]+)$")
host = host:match("^%[(.-)%]$") or host
port = tonumber(port) port = tonumber(port)
end end
local id = driver.listen(host, port, backlog) local id = driver.listen(host, port, backlog)

View File

@@ -39,7 +39,8 @@ local function open_channel(t, key)
end end
local succ, err, c local succ, err, c
if address then if address then
local host, port = string.match(address, "([^:]+):(.*)$") local host, port = string.match(address, "(.+):([^:]+)$")
host = host:match("^%[(.-)%]$") or host
c = node_sender[key] c = node_sender[key]
if c == nil then if c == nil then
c = skynet.newservice("clustersender", key, nodename, host, port) c = skynet.newservice("clustersender", key, nodename, host, port)
@@ -147,6 +148,7 @@ function command.listen(source, addr, port, maxclient)
if port == nil then if port == nil then
local address = assert(node_address[addr], addr .. " is down") local address = assert(node_address[addr], addr .. " is down")
addr, port = string.match(address, "(.+):([^:]+)$") addr, port = string.match(address, "(.+):([^:]+)$")
addr = addr:match("^%[(.-)%]$") or addr
port = tonumber(port) port = tonumber(port)
assert(port ~= 0) assert(port ~= 0)
skynet.call(gate, "lua", "open", { address = addr, port = port, maxclient = maxclient }) skynet.call(gate, "lua", "open", { address = addr, port = port, maxclient = maxclient })