add skynet.context and enhance debug console command service

This commit is contained in:
Cloud Wu
2018-09-06 18:59:33 +08:00
parent c4334be9c3
commit c96e20e6c3
3 changed files with 34 additions and 7 deletions

View File

@@ -439,6 +439,12 @@ function skynet.ret(msg, sz)
return ret
end
function skynet.context()
local co_session = session_coroutine_id[running_thread]
local co_address = session_coroutine_address[running_thread]
return co_session, co_address
end
function skynet.ignoreret()
-- We use session for other uses
session_coroutine_id[running_thread] = nil
@@ -782,6 +788,14 @@ function skynet.stat(what)
end
function skynet.task(ret)
if type(ret) == "number" then
local co = session_id_coroutine[ret]
if co then
return debug.traceback(co)
else
return "No session"
end
end
local t = 0
for session,co in pairs(session_id_coroutine) do
if ret then

View File

@@ -32,10 +32,14 @@ local function init(skynet, export)
skynet.ret(skynet.pack(stat))
end
function dbgcmd.TASK()
local task = {}
skynet.task(task)
skynet.ret(skynet.pack(task))
function dbgcmd.TASK(session)
if session then
skynet.ret(skynet.pack(skynet.task(session)))
else
local task = {}
skynet.task(task)
skynet.ret(skynet.pack(task))
end
end
function dbgcmd.INFO(...)

View File

@@ -16,7 +16,7 @@ local function request(name, func, ...)
end
for _,v in ipairs(s) do
skynet.wakeup(v)
skynet.wakeup(v.co)
end
if ok then
@@ -47,7 +47,12 @@ local function waitfor(name , func, ...)
return request(name, func, ...)
end
table.insert(s, co)
local session, source = skynet.context()
table.insert(s, {
co = co,
session = session,
source = source,
})
skynet.wait()
s = service[name]
if type(s) == "string" then
@@ -91,7 +96,11 @@ local function list_service()
if type(v) == "string" then
v = "Error: " .. v
elseif type(v) == "table" then
v = "Querying"
local querying = { "Querying:" }
for _, detail in ipairs(v) do
table.insert(querying, skynet.address(detail.source) .. " " .. tostring(skynet.call(detail.source, "debug", "TASK", detail.session)))
end
v = table.concat(querying, "\n")
else
v = skynet.address(v)
end