现在以一个例子测试这个问题。
# vi examples/main.lua
local skynet = require "skynet"
local sprotoloader = require "sprotoloader"
local max_client = 64
skynet.start(function()
skynet.error("Server start")
skynet.uniqueservice("protoloader")
if not skynet.getenv "daemon" then
local console = skynet.newservice("console")
end
skynet.newservice("debug_console",8000)
skynet.newservice("simpledb")
skynet.newservice("test") -- 新加了这个服务
local watchdog = skynet.newservice("watchdog")
skynet.call(watchdog, "lua", "start", {
port = 8888,
maxclient = max_client,
nodelay = true,
})
skynet.error("Watchdog listen on", 8888)
skynet.exit()
end)
# vi examples/test.lua
local skynet = require "skynet"
skynet.start(function()
skynet.fork(function()
while true do
local t={}
end
end)
end)
# ./skynet examples/config
[:01000001] LAUNCH logger
[:01000002] LAUNCH snlua bootstrap
[:01000003] LAUNCH snlua launcher
[:01000004] LAUNCH snlua cmaster
[:01000005] LAUNCH snlua cslave
[:01000007] LAUNCH snlua datacenterd
[:01000008] LAUNCH snlua service_mgr
[:01000009] LAUNCH snlua main
[:0100000a] LAUNCH snlua protoloader
[:0100000b] LAUNCH snlua console
[:0100000c] LAUNCH snlua debug_console 8000
[:0100000d] LAUNCH snlua simpledb
[:0100000e] LAUNCH snlua test
[:0100000f] LAUNCH snlua watchdog
[:01000010] LAUNCH snlua gate
[:01000010] Listen on 0.0.0.0:8888
[:01000009] Watchdog listen on 8888
[:01000009] KILL self
[:01000002] KILL self
[:00000000] A message from [ :00000000 ] to [ :0100000e ] maybe in an endless loop (version = 33)
[:00000000] A message from [ :00000000 ] to [ :0100000e ] maybe in an endless loop (version = 33)
[:00000000] A message from [ :00000000 ] to [ :0100000e ] maybe in an endless loop (version = 33)
# nc 127.0.0.1 8000
Welcome to skynet console
signal :0100000e
OK
[:0100000e] recv a signal 0
[:0100000e] lua call [0 to :100000e : 1 msgsz = 0] error : ./lualib/skynet.lua:516: ./lualib/skynet.lua:155: nil
stack traceback:
./examples/test.lua:6: in upvalue 'func'
./lualib/skynet.lua:452: in upvalue 'f'
./lualib/skynet.lua:104: in function <./lualib/skynet.lua:103>
stack traceback:
[C]: in function 'assert'
./lualib/skynet.lua:516: in function 'skynet.dispatch_message'
local skynet = require "skynet"
skynet.start(function()
skynet.fork(function()
while true do
pcall(function()
while true do
local t={}
end
end)
end
end)
end)
# ./skynet examples/config
[:01000001] LAUNCH logger
[:01000002] LAUNCH snlua bootstrap
[:01000003] LAUNCH snlua launcher
[:01000004] LAUNCH snlua cmaster
[:01000005] LAUNCH snlua cslave
[:01000006] LAUNCH harbor 1
[:01000007] LAUNCH snlua datacenterd
[:01000008] LAUNCH snlua service_mgr
[:01000009] LAUNCH snlua main
[:0100000a] LAUNCH snlua protoloader
[:0100000b] LAUNCH snlua console
[:0100000c] LAUNCH snlua debug_console 8000
[:0100000d] LAUNCH snlua simpledb
[:0100000e] LAUNCH snlua test
[:0100000f] LAUNCH snlua watchdog
[:01000010] LAUNCH snlua gate
[:01000009] KILL self
[:01000002] KILL self
[:00000000] A message from [ :00000000 ] to [ :0100000e ] maybe in an endless loop (version = 33)
[:0100000e] recv a signal 0
[:00000000] A message from [ :00000000 ] to [ :0100000e ] maybe in an endless loop (version = 33)
[:00000000] A message from [ :00000000 ] to [ :0100000e ] maybe in an endless loop (version = 33)
要怎么修改skynet的代码。方法不复杂,只需要改一处内容。
vi ./3rd/lua/lvm.c
/* Add by skynet */
lua_State * skynet_sig_L = NULL;
LUA_API void
lua_checksig_(lua_State *L) {
if (skynet_sig_L == G(L)->mainthread) {
//skynet_sig_L = NULL; 注释掉这行代码
lua_pushnil(L);
lua_error(L);
}
}
# make clean -C 3rd/lua
# make clean
# make linux
现在,再启动下skynet,然后在控制台执行一下命令。
# nc 127.0.0.1 8000
Welcome to skynet console
signal :0100000e
OK
kill :0100000e
:0100000e snlua test
OK
# ./skynet examples/config
[:01000001] LAUNCH logger
[:01000002] LAUNCH snlua bootstrap
[:01000003] LAUNCH snlua launcher
[:01000004] LAUNCH snlua cmaster
[:01000005] LAUNCH snlua cslave
[:01000006] LAUNCH harbor 1 16777221
[:01000007] LAUNCH snlua datacenterd
[:01000008] LAUNCH snlua service_mgr
[:01000009] LAUNCH snlua main
[:01000009] Server start
[:0100000a] LAUNCH snlua protoloader
[:0100000b] LAUNCH snlua console
[:0100000c] LAUNCH snlua debug_console 8000
[:0100000d] LAUNCH snlua simpledb
[:0100000e] LAUNCH snlua test
[:0100000f] LAUNCH snlua watchdog
[:01000010] LAUNCH snlua gate
[:00000000] A message from [ :00000000 ] to [ :0100000e ] maybe in an endless loop (version = 35)
[:00000000] A message from [ :00000000 ] to [ :0100000e ] maybe in an endless loop (version = 35)
[:00000000] A message from [ :00000000 ] to [ :0100000e ] maybe in an endless loop (version = 35)
[:00000000] A message from [ :00000000 ] to [ :0100000e ] maybe in an endless loop (version = 35)
[:0100000e] recv a signal 0
[:0100000e] lua call [0 to :100000e : 1 msgsz = 0] error : (no error message)
[:01000003] KILL :100000e
参考: