mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-24 20:23:06 +00:00
concurrent cluster link, fix issue #757
This commit is contained in:
@@ -14,7 +14,18 @@ local function read_response(sock)
|
|||||||
return cluster.unpackresponse(msg) -- session, ok, data, padding
|
return cluster.unpackresponse(msg) -- session, ok, data, padding
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local connecting = {}
|
||||||
|
|
||||||
local function open_channel(t, key)
|
local function open_channel(t, key)
|
||||||
|
local ct = connecting[key]
|
||||||
|
if ct then
|
||||||
|
local co = coroutine.running()
|
||||||
|
table.insert(ct, co)
|
||||||
|
skynet.wait(co)
|
||||||
|
return assert(ct.channel)
|
||||||
|
end
|
||||||
|
ct = {}
|
||||||
|
connecting[key] = ct
|
||||||
local host, port = string.match(node_address[key], "([^:]+):(.*)$")
|
local host, port = string.match(node_address[key], "([^:]+):(.*)$")
|
||||||
local c = sc.channel {
|
local c = sc.channel {
|
||||||
host = host,
|
host = host,
|
||||||
@@ -22,8 +33,16 @@ local function open_channel(t, key)
|
|||||||
response = read_response,
|
response = read_response,
|
||||||
nodelay = true,
|
nodelay = true,
|
||||||
}
|
}
|
||||||
assert(c:connect(true))
|
local succ, err = pcall(c.connect, c, true)
|
||||||
t[key] = c
|
if succ then
|
||||||
|
t[key] = c
|
||||||
|
ct.channel = c
|
||||||
|
end
|
||||||
|
connecting[key] = nil
|
||||||
|
for _, co in ipairs(ct) do
|
||||||
|
skynet.wakeup(co)
|
||||||
|
end
|
||||||
|
assert(succ, err)
|
||||||
return c
|
return c
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user