diff --git a/lualib/localgroup.lua b/lualib/localgroup.lua index 9ae09575..786f383f 100644 --- a/lualib/localgroup.lua +++ b/lualib/localgroup.lua @@ -17,7 +17,7 @@ function group.release(id) end skynet.init(function() - lg = skynet.call(".service","lua","group_local") + lg = skynet.uniqueservice("group_local") assert(lg) end, "localgroup") diff --git a/lualib/mcgroup.lua b/lualib/mcgroup.lua index be566544..6ef440f4 100644 --- a/lualib/mcgroup.lua +++ b/lualib/mcgroup.lua @@ -28,8 +28,8 @@ function group.release(id) end skynet.init(function() - SERVICE = skynet.call("SERVICE", "lua", "group_mgr") - skynet.call(".service","lua","group_agent", SERVICE) + SERVICE = skynet.uniqueservice(true, "group_mgr") + skynet.uniqueservice("group_agent", SERVICE) end, "mcgroup") return group diff --git a/lualib/redis.lua b/lualib/redis.lua index 25cd5373..1b0e22ed 100644 --- a/lualib/redis.lua +++ b/lualib/redis.lua @@ -38,7 +38,7 @@ function redis.connect(dbname) end skynet.init(function() - redis_manager = skynet.call(".service", "lua", "redis-mgr") + redis_manager = skynet.uniqueservice("redis-mgr") end, "redis") return redis diff --git a/lualib/skynet.lua b/lualib/skynet.lua index 93928f0b..e1629bc6 100644 --- a/lualib/skynet.lua +++ b/lualib/skynet.lua @@ -297,6 +297,23 @@ function skynet.newservice(name, ...) end end +function skynet.uniqueservice(global, ...) + local t = 0 + while true do + local handle + if global == true then + handle = skynet.call("SERVICE", "lua", ...) + else + handle = skynet.call(".service", "lua", global, ...) + end + if handle then + return handle + end + skynet.sleep(t) + t=t+1 + end +end + local function group_command(cmd, handle, address) if address then return string.format("%s %d :%x",cmd, handle, address) diff --git a/service/service_mgr.lua b/service/service_mgr.lua index a174b3c2..74b799d9 100644 --- a/service/service_mgr.lua +++ b/service/service_mgr.lua @@ -5,6 +5,7 @@ local service = {} local function query(service_name, ...) local s = service[service_name] if s == nil then + service[service_name] = false s = skynet.newservice(service_name, ...) service[service_name] = s end