libPhenom 是 Facebook 发布的一个C语言事件框架,用于构建高性能和高可扩展的系统。支持多线程,提供内存管理和常用数据结构(hash tables, lists, queues),json处理。
俗话说的好:
熟读代码3百变,不会淫诗也会变。
小伙子,你会淫不?不会的话,你变一个来试试啊~
“闲着蛋疼”的我,于是下来研究研究,打算变一个(宿舍dota2的气氛太浓烈了,我也不容易啊)
听说
dota毁三代,摄影毁一生
当我拿起单反的时候,已经把一生毁了,我不能把三代都毁了啊!所以,你撸你的Dota,我撸我的代码。
好了,不扯淡了,开始......
###安装 从github里获取facebook的源码
git clone https://github.com/facebook/libphenom.git
###软件依赖
编译时,需要依赖下面的开发包(mac的终端安装命令)
-
pkg-config:
brew install pkg-config
-
concurrencykit:
brew install concurrencykit
-
libssl-dev:
brew install libssl-dev
或者 -
openssl-devel :
brew install openssl-devel
-
autoconf:
brew install autoconf
-
automake:
brew install automake
-
libtool:
brew install libtool
类似安装截图: 看到没,我终端上能显示个啤酒的图标哦,提示我,得喝啤酒解困啊。
###编译并安装libphenom
$ ./autogen.sh
$ ./configure
$ make
$ make check
$ sudo make install
###详细编译安装图文
$ ./autogen.sh
$ ./configure
$ make
$ make check
$ sudo make install
###开始使用 编译完毕,即可快速使用此开发库,demo案例如下:
// Always include phenom/defs.h first to correctly set up the compilation env
#include "phenom/defs.h"
#include "phenom/configuration.h"
#include "phenom/job.h"
#include "phenom/log.h"
#include "phenom/sysutil.h"
int main(int argc, char **argv)
{
// Must be called prior to calling any other phenom functions
ph_library_init();
// Optional config file for tuning internals
ph_config_load_config_file("/path/to/my/config.json");
// Enable the non-blocking IO manager
ph_nbio_init(0);
// Do stuff here to register client/server stuff.
// This enables a very simple request/response console
// that allows you to run diagnostic commands:
// `echo memory | nc -UC /tmp/phenom-debug-console`
// (on BSD systems, use `nc -Uc`!)
// The code behind this is in
// https://github.com/facebook/libphenom/blob/master/corelib/debug_console.c
ph_debug_console_start("/tmp/phenom-debug-console");
// Run
ph_sched_run();
return 0;
}
###编译运行此demo gcc -O2 main.c pkg-config libphenom --cflags --libs
编译完成,产生a.out
文件。
更多的使用,有待我进一步去理解,源码面前了无秘密,加油。 有对此文档研究的朋友,可以加个一起学习!
具体的代码介绍文档: libPhenom