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 ...
随机推荐
- BZOJ_1010_[HNOI2008]_玩具装箱toy_(斜率优化动态规划+单调队列)
描述 http://www.lydsy.com/JudgeOnline/problem.php?id=1010 给出\(n\)和\(l\).有\(n\)个玩具,第\(i\)个玩具的长度是\(c[i]\ ...
- Azure Site Recovery 通过一键式流程将虚拟机故障转移至 Azure虚拟机
Ruturaj Dhekane 云 + Enterprise 项目经理 现在,AzureSite Recovery可以通过其"灾难恢复至 Azure"功能保护您的工作负荷,并 ...
- .net HTMLParser详细使用说明 强大的Filter类 解析HTML文档如此简单
背景: HTMLParser原本是一个在sourceforge上的一个Java开源项目,使用这个Java类库可以用来线性地或嵌套地解析HTML文本.他的 功能强大和开源等特性吸引了大量Web信息提取的 ...
- android 后台附件下载
在service中通过在oncreat()中开启一个线程,轮训ArrayList<AttachmentTask> 我这个附件下载的任务list ,ArrayList<Attachme ...
- 《C程序设计语言现代方法》第5章 编程题
1 编写一个程序,确定一个数的位数. #include <stdio.h> int main() { ; ) { cnt++; } printf("%d\n", cnt ...
- C#语法知识笔记
抽象类 1.抽象类没有方法体,直接在括号后加“;”. protected abstract string getShoutSound(); 2.抽象类不能实例化:抽象方法必须被子类重写:如果类中包含抽 ...
- 【原】 Spark中Task的提交源码解读
版权声明:本文为原创文章,未经允许不得转载. 复习内容: Spark中Stage的提交 http://www.cnblogs.com/yourarebest/p/5356769.html Spark中 ...
- 【HTML】Beginner6:Link
1.Link HTML wich basically means a system of linked text link to another HTML file or any file a ...
- Excel中VBA 连接 数据库 方法- 摘自网络
Sub GetData() Dim strConn As String, strSQL As String Dim conn As ADODB.Connection Dim ds As ADODB.R ...
- POJ1751--Highways(最小生成树,kauskal)
裸最小生成树.用kauskal做方便一些. 不得不说这么大数据用cin cout 真是作死..活该T那么多次... /***************************************** ...