规则
- 缩进表示被调用;
-
: 表示依赖;
-
^: 表示弱依赖;
-
'''...'''表示块注释;
-
# 开始的行为行注释;
- foo()表示调用foo函数。
# 由c main函数启动。
main()
# 从命令行参数中读入配置文件路径,初始化skynet_config。
init skynet_config : config-file
# 启动。所有的启动代码都在这个函数里。
skynet_start() : skynet_config
# 初始化c模块查找路径。
skynet_module_init() : skynet_config.module_path : config-file.cpath
# 使用./cservice/logger.so创建Context。logger是日志模块。
skynet_context_new(logger)
: skynet_config.logservice : config-file.logservice
: skynet_config.logger : config-file.logger
# 示例中传入的参数为"snlua bootstrap",这是配置文件的bootstrap项。
bootstrap() : skynet_config.bootstrap : config-file.bootstrap
# 使用./cservice/snlua.so创建Context。snlua是lua初始化模块。
skynet_context_new(snlua)
'''
service_snlua.c
snlua is the lua booter.
'''
# 初始化lua。
snlua_init()
# 初始化是个消息。由这里发送出去。
skynet_send()
# 由于现在worker还没启动,初始化消息只能手动分发一次来处理。
skynet_context_dispatchall()
'''
dispatch all message before start. here will dispatch init message.
'''
# snlua的消息回调函数。
launch_cb()
init_cb()
# 初始化lua。
init lua
# 创建codecache模块;直接用c创建模块,用得太醇熟了。
create module "skynet.codecache"
# 设置一些全局变量。
set lua paths
LUA_PATH : environment.lua_path ^: config-file.lua_path
LUA_CPATH : environment.lua_cpath ^: config-file.lua_cpath
LUA_SERVICE : environment.luaservice ^: config-file.luaservice
LUA_PRELOAD : environment.preload ^: config-file.preload
# 加载./lualib/loader.lua模块。
load loader : ./lualib/loader.lua
'''
# 先加载LUA_PRELOAD中的模块,再加载指定模块。
1. load all preload lua modules.
2. load specific lua module.
'''
# 使用loader加载./service/bootstrap.lua。
loader("bootstrap") : ./service/bootstrap.lua
# bootstrap启动了其他的服务。
# 创建线程并等待线程结束。
start() : skynet_config.thread
create monitor thread
'''
loop message monitor.
'''
create timer thread
'''
timer event -> skynet message
'''
create network thread
'''
network message -> skynet message
'''
create worker thread
'''
skynet message dispatcher
'''
join all threads
总结
- 读取config。
- 加载logger。
- 加载snlua。
- 创建线程并等待。