skynet
skynet copied to clipboard
在agent服务中使用了一个local表,各种花式crash
agent服务,处理client的请求,
local db = {}
function REQUEST:get(args) log(db) print("get", args.what) --local r = skynet.call("SIMPLEDB", "lua", "get", args.what)
--print(db[args.what])
print('----------------------')
--log(db)
return { result = "haha fake" }
end
function REQUEST:set(args)
-- local r = skynet.call("SIMPLEDB", "lua", "set", args.what, args.value)
db[args.what] = args.value;
// 就是这里了,如果不赋值就不会报crash
// 这里还有一个crash,就是把上面的get也打开,就更容易crash了
--print(db[args.what])
log(db)
end
local function request(name, args, response)
print(name, args, response)
if not env.module then
log('module dose not exist error')
return nil
end
-- 我们假设每一个name都是唯一的,也许未来要写一个工具,TODO 来检测proto中的name/tag都是唯一的
for _, v in pairs(env.module) do
local request = v.request
if type(request) == "table" then
local cb = request[name]
if cb ~= nil and type(cb) == "function" then
local isok, ret = pcall(cb, '', args)
if isok then
if response then
return response(ret)
else
return nil
end
end
end
end
end
return nil