mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-24 12:20:41 +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))
|
skynet.error(string.format("Attach to :%08x", address))
|
||||||
local handle
|
local handle
|
||||||
channel, handle = debugchannel.create()
|
channel, handle = debugchannel.create()
|
||||||
skynet.call(address, "debug", "REMOTEDEBUG", fd, handle)
|
local ok, err = pcall(skynet.call, address, "debug", "REMOTEDEBUG", fd, handle)
|
||||||
-- todo hook
|
if not ok then
|
||||||
skynet.ret(skynet.pack(nil))
|
skynet.ret(skynet.pack(false, "Debugger attach failed"))
|
||||||
|
else
|
||||||
|
-- todo hook
|
||||||
|
skynet.ret(skynet.pack(true))
|
||||||
|
end
|
||||||
skynet.exit()
|
skynet.exit()
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -20,6 +24,10 @@ function CMD.cmd(cmdline)
|
|||||||
channel:write(cmdline)
|
channel:write(cmdline)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function CMD.ping()
|
||||||
|
skynet.ret()
|
||||||
|
end
|
||||||
|
|
||||||
skynet.start(function()
|
skynet.start(function()
|
||||||
skynet.dispatch("lua", function(_,_,cmd,...)
|
skynet.dispatch("lua", function(_,_,cmd,...)
|
||||||
local f = CMD[cmd]
|
local f = CMD[cmd]
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ end
|
|||||||
local function console_main_loop(stdin, print)
|
local function console_main_loop(stdin, print)
|
||||||
print("Welcome to skynet console")
|
print("Welcome to skynet console")
|
||||||
skynet.error(stdin, "connected")
|
skynet.error(stdin, "connected")
|
||||||
pcall(function()
|
local ok, err = pcall(function()
|
||||||
while true do
|
while true do
|
||||||
local cmdline = socket.readline(stdin, "\n")
|
local cmdline = socket.readline(stdin, "\n")
|
||||||
if not cmdline then
|
if not cmdline then
|
||||||
@@ -109,6 +109,9 @@ local function console_main_loop(stdin, print)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
if not ok then
|
||||||
|
skynet.error(stdin, err)
|
||||||
|
end
|
||||||
skynet.error(stdin, "disconnected")
|
skynet.error(stdin, "disconnected")
|
||||||
socket.close(stdin)
|
socket.close(stdin)
|
||||||
end
|
end
|
||||||
@@ -262,8 +265,11 @@ function COMMANDX.debug(cmd)
|
|||||||
local address = adjust_address(cmd[2])
|
local address = adjust_address(cmd[2])
|
||||||
local agent = skynet.newservice "debug_agent"
|
local agent = skynet.newservice "debug_agent"
|
||||||
local stop
|
local stop
|
||||||
skynet.fork(function()
|
local term_co = coroutine.running()
|
||||||
|
local function forward_cmd()
|
||||||
repeat
|
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")
|
local cmdline = socket.readline(cmd.fd, "\n")
|
||||||
cmdline = cmdline and cmdline:gsub("(.*)\r$", "%1")
|
cmdline = cmdline and cmdline:gsub("(.*)\r$", "%1")
|
||||||
if not cmdline then
|
if not cmdline then
|
||||||
@@ -272,9 +278,19 @@ function COMMANDX.debug(cmd)
|
|||||||
end
|
end
|
||||||
skynet.send(agent, "lua", "cmd", cmdline)
|
skynet.send(agent, "lua", "cmd", cmdline)
|
||||||
until stop or cmdline == "cont"
|
until stop or cmdline == "cont"
|
||||||
|
end
|
||||||
|
skynet.fork(function()
|
||||||
|
pcall(forward_cmd)
|
||||||
|
skynet.wakeup(term_co)
|
||||||
end)
|
end)
|
||||||
skynet.call(agent, "lua", "start", address, cmd.fd)
|
local ok, err = skynet.call(agent, "lua", "start", address, cmd.fd)
|
||||||
stop = true
|
stop = true
|
||||||
|
-- wait for fork coroutine exit.
|
||||||
|
skynet.wait(term_co)
|
||||||
|
|
||||||
|
if not ok then
|
||||||
|
error(err)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function COMMAND.logon(address)
|
function COMMAND.logon(address)
|
||||||
|
|||||||
Reference in New Issue
Block a user