mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-24 12:20:41 +00:00
add more info when service init blocked
This commit is contained in:
@@ -6,6 +6,7 @@ local string = string
|
||||
local services = {}
|
||||
local command = {}
|
||||
local instance = {} -- for confirm (function command.LAUNCH / command.ERROR / command.LAUNCHOK)
|
||||
local launch_session = {} -- for command.QUERY, service_address -> session
|
||||
|
||||
local function handle_to_address(handle)
|
||||
return tonumber("0x" .. string.sub(handle , 2))
|
||||
@@ -68,6 +69,7 @@ function command.REMOVE(_, handle, kill)
|
||||
-- instance is dead
|
||||
response(not kill) -- return nil to caller of newservice, when kill == false
|
||||
instance[handle] = nil
|
||||
launch_session[handle] = nil
|
||||
end
|
||||
|
||||
-- don't return (skynet.ret) because the handle may exit
|
||||
@@ -77,10 +79,12 @@ end
|
||||
local function launch_service(service, ...)
|
||||
local param = table.concat({...}, " ")
|
||||
local inst = skynet.launch(service, param)
|
||||
local session = skynet.context()
|
||||
local response = skynet.response()
|
||||
if inst then
|
||||
services[inst] = service .. " " .. param
|
||||
instance[inst] = response
|
||||
launch_session[inst] = session
|
||||
else
|
||||
response(false)
|
||||
return
|
||||
@@ -107,6 +111,7 @@ function command.ERROR(address)
|
||||
local response = instance[address]
|
||||
if response then
|
||||
response(false)
|
||||
launch_session[address] = nil
|
||||
instance[address] = nil
|
||||
end
|
||||
services[address] = nil
|
||||
@@ -119,11 +124,20 @@ function command.LAUNCHOK(address)
|
||||
if response then
|
||||
response(true, address)
|
||||
instance[address] = nil
|
||||
launch_session[address] = nil
|
||||
end
|
||||
|
||||
return NORET
|
||||
end
|
||||
|
||||
function command.QUERY(_, request_session)
|
||||
for address, session in pairs(launch_session) do
|
||||
if session == request_session then
|
||||
return address
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- for historical reasons, launcher support text command (for C service)
|
||||
|
||||
skynet.register_protocol {
|
||||
|
||||
Reference in New Issue
Block a user