skynet examples深入学习

examples/skynet.lua   

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")
	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)

config 中配置 start = "main" 所以会从package.path中找到这个main.lua (万一有多个main.lua是不是加载第一个找到的呢?)

执行这个脚本前,启动了如下几个服务:

logger服务;

newservice( snlua, bootstrap):

     加载 snlua module;

     使用snlua动态库中的 create init init_cb几个流程完成了: 加载 bootstrap.lua,并执行一次的过程。

bootstrap.lua:使命:

     1. 使用skynet.start() 注册了一个服务启动函数,并投递一个请求初始化的消息,等待框架从dispatch_message那边回调。

     2. bootstrap中启动 launcher服务;
               2.1 config.harbor_id == 0 && config.standalone==nil : 启动cdummy 服务(name:".cslave"), datacenterd服务

               2.2 config.harbor_id [1,255]: cmaster服务 ; cslave服务(启动harbor服务), 若standalone有配置,启动 datacenterd服务

     注:standalone这家伙和字面意义不大一样。

  • standalone 如果把这个 skynet 进程作为主进程启动(skynet 可以由分布在多台机器上的多个进程构成网络),那么需要配置standalone 这一项,表示这个进程是主节点,它需要开启一个控制中心,监听一个端口,让其它节点接入。

     3.启动service_mgr服务, 命名 ".service"

     4.启动 config.start 服务。 可配置, 若未配置, 默认启动 "main.lua" 中的服务

     至此,使命完成,自我终结, skynet.exit() 。

-------------------------------------------------------------------------------------------------------------

正式进入main.lua流程:

1.启动protoloader 服务: 把开源的sproto库 require进来,并加载协议文件。

2.debug_console

3.simpledb服务。

4.watchdog服务,随后立马给自己发了继init(skynet.start 发出)之后的第二条消息start
至此,main服务使命结束,自我终结 skynet.exit(),
世界交给了 watchdog, debug_console, simpledb 三位主演.幕后的的先不关心吧。

---------------------------------------------------------------------------------------------------------------





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值