From b2d82373639cf2b3902f23078559b9945d19c023 Mon Sep 17 00:00:00 2001 From: Cloud Wu Date: Thu, 23 Jul 2015 18:23:47 +0800 Subject: [PATCH] improve unregister protocol error report --- lualib/skynet.lua | 20 ++++++++++++++++---- lualib/skynet/debug.lua | 4 ++++ 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/lualib/skynet.lua b/lualib/skynet.lua index 02a966fb..cbc16034 100644 --- a/lualib/skynet.lua +++ b/lualib/skynet.lua @@ -415,9 +415,13 @@ function skynet.wakeup(co) end function skynet.dispatch(typename, func) - local p = assert(proto[typename],tostring(typename)) - assert(p.dispatch == nil, tostring(typename)) - p.dispatch = func + local p = proto[typename] + if func then + assert(p and (p.dispatch == nil), tostring(typename)) + p.dispatch = func + else + return p and p.dispatch + end end local function unknown_request(session, address, msg, sz, prototype) @@ -466,7 +470,15 @@ local function raw_dispatch_message(prototype, msg, sz, session, source, ...) suspend(co, coroutine.resume(co, true, msg, sz)) end else - local p = assert(proto[prototype], prototype) + local p = proto[prototype] + if p == nil then + if session ~= 0 then + c.send(source, skynet.PTYPE_ERROR, session, "") + else + unknown_request(session, source, msg, sz, prototype) + end + return + end local f = p.dispatch if f then local ref = watching_service[source] diff --git a/lualib/skynet/debug.lua b/lualib/skynet/debug.lua index 0bcb8edb..6c040c24 100644 --- a/lualib/skynet/debug.lua +++ b/lualib/skynet/debug.lua @@ -63,6 +63,10 @@ function dbgcmd.REMOTEDEBUG(...) remotedebug.start(export, ...) end +function dbgcmd.SUPPORT(pname) + return skynet.ret(skynet.pack(skynet.dispatch(pname) ~= nil)) +end + local function _debug_dispatch(session, address, cmd, ...) local f = dbgcmd[cmd] assert(f, cmd)