mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-24 20:23:06 +00:00
add cluster.proxy and cluster.ncall
This commit is contained in:
@@ -4,7 +4,7 @@ local clusterd
|
||||
local cluster = {}
|
||||
|
||||
function cluster.call(node, address, ...)
|
||||
-- skynet.pack(...) will free by cluster.c.packrequest
|
||||
-- skynet.pack(...) will free by cluster.core.packrequest
|
||||
return skynet.call(clusterd, "lua", "req", node, address, skynet.pack(...))
|
||||
end
|
||||
|
||||
@@ -20,6 +20,23 @@ function cluster.reload()
|
||||
skynet.call(clusterd, "lua", "reload")
|
||||
end
|
||||
|
||||
function cluster.proxy(node, name)
|
||||
return skynet.call(clusterd, "lua", "proxy", node, name)
|
||||
end
|
||||
|
||||
local namecache = {}
|
||||
|
||||
function cluster.ncall(name, ...)
|
||||
local s = namecache[name]
|
||||
if not s then
|
||||
local node , lname = name:match "(.-)(%..+)"
|
||||
assert(node and lname)
|
||||
s = cluster.proxy(node, lname)
|
||||
namecache[name] = assert(s)
|
||||
end
|
||||
return skynet.call(s, "lua", ...)
|
||||
end
|
||||
|
||||
skynet.init(function()
|
||||
clusterd = skynet.uniqueservice("clusterd")
|
||||
end)
|
||||
|
||||
@@ -99,6 +99,7 @@ local coroutine_yield = coroutine.yield
|
||||
local function co_create(f)
|
||||
local co = table.remove(coroutine_pool)
|
||||
if co == nil then
|
||||
local print = print
|
||||
co = coroutine.create(function(...)
|
||||
f(...)
|
||||
while true do
|
||||
@@ -548,7 +549,7 @@ end
|
||||
|
||||
function skynet.address(addr)
|
||||
if type(addr) == "number" then
|
||||
return string.format(":%x",addr)
|
||||
return string.format(":%08x",addr)
|
||||
else
|
||||
return tostring(addr)
|
||||
end
|
||||
@@ -648,6 +649,21 @@ function skynet.filter(f ,start_func)
|
||||
end)
|
||||
end
|
||||
|
||||
function skynet.forward_type(map, start_func)
|
||||
c.callback(function(ptype, msg, sz, ...)
|
||||
local prototype = map[ptype]
|
||||
if prototype then
|
||||
dispatch_message(prototype, msg, sz, ...)
|
||||
else
|
||||
dispatch_message(ptype, msg, sz, ...)
|
||||
c.trash(msg, sz)
|
||||
end
|
||||
end, true)
|
||||
skynet.timeout(0, function()
|
||||
init_service(start_func)
|
||||
end)
|
||||
end
|
||||
|
||||
function skynet.endless()
|
||||
return c.command("ENDLESS")~=nil
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user