mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-22 02:53:09 +00:00
bugfix isse #592
This commit is contained in:
@@ -10,9 +10,13 @@ function CMD.start(address, fd)
|
||||
skynet.error(string.format("Attach to :%08x", address))
|
||||
local handle
|
||||
channel, handle = debugchannel.create()
|
||||
skynet.call(address, "debug", "REMOTEDEBUG", fd, handle)
|
||||
-- todo hook
|
||||
skynet.ret(skynet.pack(nil))
|
||||
local ok, err = pcall(skynet.call, address, "debug", "REMOTEDEBUG", fd, handle)
|
||||
if not ok then
|
||||
skynet.ret(skynet.pack(false, "Debugger attach failed"))
|
||||
else
|
||||
-- todo hook
|
||||
skynet.ret(skynet.pack(true))
|
||||
end
|
||||
skynet.exit()
|
||||
end
|
||||
|
||||
@@ -20,6 +24,10 @@ function CMD.cmd(cmdline)
|
||||
channel:write(cmdline)
|
||||
end
|
||||
|
||||
function CMD.ping()
|
||||
skynet.ret()
|
||||
end
|
||||
|
||||
skynet.start(function()
|
||||
skynet.dispatch("lua", function(_,_,cmd,...)
|
||||
local f = CMD[cmd]
|
||||
|
||||
@@ -91,7 +91,7 @@ end
|
||||
local function console_main_loop(stdin, print)
|
||||
print("Welcome to skynet console")
|
||||
skynet.error(stdin, "connected")
|
||||
pcall(function()
|
||||
local ok, err = pcall(function()
|
||||
while true do
|
||||
local cmdline = socket.readline(stdin, "\n")
|
||||
if not cmdline then
|
||||
@@ -109,6 +109,9 @@ local function console_main_loop(stdin, print)
|
||||
end
|
||||
end
|
||||
end)
|
||||
if not ok then
|
||||
skynet.error(stdin, err)
|
||||
end
|
||||
skynet.error(stdin, "disconnected")
|
||||
socket.close(stdin)
|
||||
end
|
||||
@@ -262,8 +265,11 @@ function COMMANDX.debug(cmd)
|
||||
local address = adjust_address(cmd[2])
|
||||
local agent = skynet.newservice "debug_agent"
|
||||
local stop
|
||||
skynet.fork(function()
|
||||
local term_co = coroutine.running()
|
||||
local function forward_cmd()
|
||||
repeat
|
||||
-- notice : It's a bad practice to call socket.readline from two threads (this one and console_main_loop), be careful.
|
||||
skynet.call(agent, "lua", "cmd", "ping") -- detect agent alive, if agent exit, raise error
|
||||
local cmdline = socket.readline(cmd.fd, "\n")
|
||||
cmdline = cmdline and cmdline:gsub("(.*)\r$", "%1")
|
||||
if not cmdline then
|
||||
@@ -272,9 +278,19 @@ function COMMANDX.debug(cmd)
|
||||
end
|
||||
skynet.send(agent, "lua", "cmd", cmdline)
|
||||
until stop or cmdline == "cont"
|
||||
end
|
||||
skynet.fork(function()
|
||||
pcall(forward_cmd)
|
||||
skynet.wakeup(term_co)
|
||||
end)
|
||||
skynet.call(agent, "lua", "start", address, cmd.fd)
|
||||
local ok, err = skynet.call(agent, "lua", "start", address, cmd.fd)
|
||||
stop = true
|
||||
-- wait for fork coroutine exit.
|
||||
skynet.wait(term_co)
|
||||
|
||||
if not ok then
|
||||
error(err)
|
||||
end
|
||||
end
|
||||
|
||||
function COMMAND.logon(address)
|
||||
|
||||
Reference in New Issue
Block a user