mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-24 12:20:41 +00:00
add skynet.harbor.linkmaster
This commit is contained in:
@@ -1,9 +1,16 @@
|
|||||||
local skynet = require "skynet"
|
local skynet = require "skynet"
|
||||||
|
local harbor = require "skynet.harbor"
|
||||||
|
|
||||||
|
local function monitor_master()
|
||||||
|
harbor.linkmaster()
|
||||||
|
print("master is down")
|
||||||
|
skynet.exit()
|
||||||
|
end
|
||||||
|
|
||||||
skynet.start(function()
|
skynet.start(function()
|
||||||
print("Log server start")
|
print("Log server start")
|
||||||
skynet.monitor "simplemonitor"
|
skynet.monitor "simplemonitor"
|
||||||
local log = skynet.newservice("globallog")
|
local log = skynet.newservice("globallog")
|
||||||
skynet.exit()
|
skynet.fork(monitor_master)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
|||||||
@@ -19,4 +19,8 @@ function harbor.connect(id)
|
|||||||
skynet.call(".cslave", "lua", "CONNECT", id)
|
skynet.call(".cslave", "lua", "CONNECT", id)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function harbor.linkmaster()
|
||||||
|
skynet.call(".cslave", "lua", "LINKMASTER")
|
||||||
|
end
|
||||||
|
|
||||||
return harbor
|
return harbor
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ local queryname = {}
|
|||||||
local harbor = {}
|
local harbor = {}
|
||||||
local harbor_service
|
local harbor_service
|
||||||
local monitor = {}
|
local monitor = {}
|
||||||
|
local monitor_master_set = {}
|
||||||
|
|
||||||
local function read_package(fd)
|
local function read_package(fd)
|
||||||
local sz = socket.read(fd, 1)
|
local sz = socket.read(fd, 1)
|
||||||
@@ -99,6 +100,9 @@ local function monitor_master(master_fd)
|
|||||||
end
|
end
|
||||||
else
|
else
|
||||||
skynet.error("Master disconnect")
|
skynet.error("Master disconnect")
|
||||||
|
for _, v in ipairs(monitor_master_set) do
|
||||||
|
v(true)
|
||||||
|
end
|
||||||
socket.close(master_fd)
|
socket.close(master_fd)
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
@@ -183,6 +187,10 @@ function harbor.LINK(fd, id)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function harbor.LINKMASTER()
|
||||||
|
table.insert(monitor_master_set, skynet.response())
|
||||||
|
end
|
||||||
|
|
||||||
function harbor.CONNECT(fd, id)
|
function harbor.CONNECT(fd, id)
|
||||||
if not slaves[id] then
|
if not slaves[id] then
|
||||||
if monitor[id] == nil then
|
if monitor[id] == nil then
|
||||||
|
|||||||
Reference in New Issue
Block a user