mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-24 03:53:09 +00:00
remove skynet.watch, move simplemonitor to examples
This commit is contained in:
@@ -4,7 +4,6 @@ local max_client = 64
|
||||
|
||||
skynet.start(function()
|
||||
print("Server start")
|
||||
skynet.monitor "simplemonitor"
|
||||
local console = skynet.newservice("console")
|
||||
skynet.newservice("debug_console",8000)
|
||||
skynet.newservice("simpledb")
|
||||
|
||||
39
examples/simplemonitor.lua
Normal file
39
examples/simplemonitor.lua
Normal file
@@ -0,0 +1,39 @@
|
||||
local skynet = require "skynet"
|
||||
|
||||
-- It's a simple service exit monitor, you can do something more when a service exit.
|
||||
|
||||
local service_map = {}
|
||||
|
||||
skynet.register_protocol {
|
||||
name = "client",
|
||||
id = skynet.PTYPE_CLIENT, -- PTYPE_CLIENT = 3
|
||||
unpack = function() end,
|
||||
dispatch = function(_, address)
|
||||
local w = service_map[address]
|
||||
if w then
|
||||
for watcher in pairs(w) do
|
||||
skynet.redirect(watcher, address, "error", "")
|
||||
end
|
||||
service_map[address] = false
|
||||
end
|
||||
end
|
||||
}
|
||||
|
||||
local function monitor(session, watcher, command, service)
|
||||
assert(command, "WATCH")
|
||||
local w = service_map[service]
|
||||
if not w then
|
||||
if w == false then
|
||||
skynet.ret(skynet.pack(false))
|
||||
return
|
||||
end
|
||||
w = {}
|
||||
service_map[service] = w
|
||||
end
|
||||
w[watcher] = true
|
||||
skynet.ret(skynet.pack(true))
|
||||
end
|
||||
|
||||
skynet.start(function()
|
||||
skynet.dispatch("lua", monitor)
|
||||
end)
|
||||
Reference in New Issue
Block a user