skynet是什么
struct skynet_context *
skynet_context_new(const char * name, const char *param) {
// 装载模块
struct skynet_module * mod = skynet_module_query(name); if (mod == NULL)
return NULL; void *inst = skynet_module_instance_create(mod);
if (inst == NULL)
return NULL;
// 初始化skynet_context实例
struct skynet_context * ctx = skynet_malloc(sizeof(*ctx));
CHECKCALLING_INIT(ctx) ctx->mod = mod;
ctx->instance = inst;
ctx->ref = ;
ctx->cb = NULL;
ctx->cb_ud = NULL;
ctx->session_id = ;
ctx->logfile = NULL; ctx->init = false;
ctx->endless = false;
// 初始化服务handle
// Should set to 0 first to avoid skynet_handle_retireall get an uninitialized handle
ctx->handle = ;
ctx->handle = skynet_handle_register(ctx);
// 初始化消息队列
struct message_queue * queue = ctx->queue = skynet_mq_create(ctx->handle);
// init function maybe use ctx->handle, so it must init at last
context_inc(); CHECKCALLING_BEGIN(ctx)
int r = skynet_module_instance_init(mod, inst, ctx, param);
CHECKCALLING_END(ctx)
if (r == ) {
struct skynet_context * ret = skynet_context_release(ctx);
if (ret) {
ctx->init = true;
}
skynet_globalmq_push(queue);
if (ret) {
skynet_error(ret, "LAUNCH %s %s", name, param ? param : "");
}
return ret;
} else {
skynet_error(ctx, "FAILED launch %s", name);
uint32_t handle = ctx->handle;
skynet_context_release(ctx);
skynet_handle_retire(handle);
struct drop_t d = { handle };
skynet_mq_release(queue, drop_message, &d);
return NULL;
}
}
在skynet_handle_register方法中生成一个服务handle,handle是一个32位的整数,在生成handle的时候,是把该节点的harbor id写到了handle的高8位里面,所以一个服务的handle,就可以知道这个服务是哪个节点的。
s->handle_index = handle + ;
rwlock_wunlock(&s->lock);
handle |= s->harbor;
return handle;
int skynet_send(
struct skynet_context * context,
uint32_t source,
uint32_t destination,
int type,
int session,
void * msg,
size_t sz
); typedef int (*skynet_cb)(
struct skynet_context * context,
void *ud,
int type,
int session,
uint32_t source ,
const void * msg,
size_t sz
);
参考:Skynet 设计综述
skynet是什么的更多相关文章
- skynet的协程
之前对skynet的印象,主要是来自于我对golang的理解,对gevent开发的经验,以及云风的blog.对于底层的代码,并没有仔细去阅读过.最近在实现业务系统的时候,发现有同事在同一个函数里做了一 ...
- Skynet Pomelo Erlang Elixir 的认识
1.skynet pomelo(node.js) elixir(erlang) 周末研究总结 手游这两年发展来看,感觉对实时性要求越来越高,有同事在研究Elixir开发,google得知这东西是基于e ...
- 转:云风skynet服务端框架研究
转: http://forthxu.com/blog/skynet.html skynet是云风编写的服务端底层管理框架,底层由C编写,配套lua作为脚本使用,可换python等其他脚本语言.sky ...
- skynet启动过程_bootstrap
这遍摘自skynet 的wiki skynet 由一个或多个进程构成,每个进程被称为一个 skynet 节点.本文描述了 skynet 节点的启动流程. skynet 节点通过运行 skynet 主程 ...
- skynet启动过程_1
skynet的启动时需带个配置文件,这个文件其实是作为lua全局变量用的,见 int main(int argc, char *argv[]) { const char * config_file = ...
- skynet网络库socket-server
最近在读大神云风的开源服务器架构skynet,其中的网络库,云风已经单独开来,可以独立使用. 开源地址: https://github.com/cloudwu/socket-server 网络库已经封 ...
- Skynet:特性收集
基于云风的 blog,收集 skynet 的特性以便将来在代码中一一验证. “ ... ” 部分节选自云风的 BLOG. 1. 基于 Erlang-Actor 模式的 C 实现 “把一个符合规范的 C ...
- skynet的流程1
logpath = "."harbor = 1address = "127.0.0.1:2526"master = "127.0.0.1:2013&q ...
- skynet newservice API参考
local skynet = require("skynet") skynet.start(start_func) c服务snlua启动后执行的第一个lua文件里面的主逻辑必定是s ...
随机推荐
- ☀【移动】UC极速模式
UC浏览器的部分版本默认是“极速”模式,有何办法能控制UC自动改变其浏览模式? √http://www.zhihu.com/question/20582949 关于UC极速模式下访问网站错乱 √htt ...
- SQL Server 2008 数据库日志文件丢失处理方法
当数据库发生这种操作故障时,可以按如下操作步骤可解决此方法,打开数据库里的Sql 查询编辑器窗口,运行以下的命令. 1.修改数据库为紧急模式 ALTER DATABASE Zhangxing SET ...
- 【转】Android source build/envsetup.sh学习笔记
原文网址:http://blog.csdn.net/mliubing2532/article/details/7567164 如果你只需要修改某一个模块的内容,但是却每次都要执行make, 最后等待很 ...
- jquery图片播放插件Fancybox(灯箱)
效果预览Demo源码下载 Fancybox的特点如下: 可以支持图片.html文本.flash动画.iframe以及ajax的支持 可以自定义播放器的CSS样式 可以以组的形式进行播放 如果将鼠标滚动 ...
- Chrome已原生支持“Chrome To Mobile”
完成PC和手机端Chrome的同gmail帐号绑定后,即可按如下操作进行: 已知在版本“19.0.1084.15”中,这个功能默认未开启,需要进入“chrome://flags/”进行手工启用(早几期 ...
- STL for_each()
http://www.cplusplus.com/reference/algorithm/for_each/ std::move()用于c++11 http://www.cplusplus.com/r ...
- python解析AMF协议
最近看公司同事在玩页游<斗破乾坤>我也进去完了一把,感觉画面还不错,就是不停的点鼠标做任务,一会就烦了,看了下前端配置文件,我们以error.json_3e30为例,这个肯定是记录错误码的 ...
- POJ2236 Wireless Network 并查集
水题 #include<cstdio> #include<cstring> #include<queue> #include<set> #include ...
- Frank自动化测试
记得是夏天的时候去参加一个infoQ的论坛,里面有一个朋友强烈推荐Frank测试框架.所以趁着年底赶紧学一下.这中间需要ruby的基础. 安装过程:1.安装frank-cucumber 命令: sud ...
- win7下安装 WINDRIVER.TORNADO.V2.2.FOR.ARM
[风河VxWorks].WINDRIVER.TORNADO.V2.2.FOR.ARM下载 http://115.com/file/dlfo8zpy http://115.com/file/c4r01l ...