1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- --[[
- Descripttion:
- version:
- Author: Neo,Huang
- Date: 2022-07-28 09:16:34
- LastEditors: Neo,Huang
- LastEditTime: 2022-07-28 09:17:33
- --]]
- local skynet = require "skynet"
- require "skynet.manager"
- local proto_type, proto_service_num = ...
- proto_service_num = tonumber(proto_service_num)
- local balance = 1
- local proto_handles = {}
- local CMD = {}
- local function service_init()
- for i = 1, proto_service_num do
- local handle = skynet.newservice("srvLoadProto", proto_type)
- if handle then
- table.insert(proto_handles, handle)
- end
- end
- end
- function CMD.get_proto_handle()
- local handle = proto_handles[balance]
- if handle then
- balance = balance + 1
- if balance > proto_service_num then
- balance = 1
- end
- end
- assert(handle, "get proto handle error!")
- return handle
- end
- function CMD.update_proto()
- for _, v in ipairs(proto_handles) do
- skynet.send(v, "lua", "update_proto")
- end
- end
- function CMD.exit()
- for _, v in ipairs(proto_handles) do
- skynet.call(v, "lua", "exit")
- end
- skynet.retpack(nil)
- skynet.exit()
- end
- skynet.dispatch(
- "lua",
- function(session, _, cmd, ...)
- local func = assert(CMD[cmd], cmd .. " not found")
- local ret = func(...)
- if session > 0 and cmd ~= "exit" then
- skynet.retpack(ret)
- end
- end
- )
- skynet.start(
- function()
- service_init()
- skynet.register(".proto_mgr")
- end
- )
|