您的位置:首页 > 其它

语言对比-事件模型

2016-01-03 13:57 239 查看
linux c下可以使用的事件库包括

libevent ,libev ,libuv,glib

libevent

https://github.com/nmathewson/Libevent

libev

案例 shadowsoks-manyuser

git clone https://github.com/MarkTseng/libev
cd libev/

mkdir __INSTALL

chmod 777 *

./autogen.sh 

./configure --prefix=/opt/libev/__INSTALL/

make

make install

find __INSTALL/

__INSTALL/

__INSTALL/share

__INSTALL/share/man

__INSTALL/share/man/man3

__INSTALL/share/man/man3/ev.3

__INSTALL/lib

__INSTALL/lib/libev.a

__INSTALL/lib/libev.so.4.0.0

__INSTALL/lib/libev.so.4

__INSTALL/lib/libev.la

__INSTALL/lib/libev.so

__INSTALL/include

__INSTALL/include/event.h

__INSTALL/include/ev.h

__INSTALL/include/ev++.h

demo.c
#include <ev.h>
#include <stdio.h>

ev_io stdin_watcher;
ev_timer timeout_watcher;

static void stdin_cb(EV_P_ ev_io *w,int revents)
{
puts ("stdin ready");
ev_io_stop(EV_A_ w);
ev_break (EV_A_ EVBREAK_ALL);
}

static void timeout_cb (EV_P_ ev_timer *w,int revents)
{
puts ("timeout");
ev_break( EV_A_ EVBREAK_ONE );
}

int main(int argc,char* argv[])
{
struct ev_loop *loop = EV_DEFAULT;

ev_io_init(&stdin_watcher,stdin_cb,0,EV_READ);
ev_io_start (loop,&stdin_watcher);

ev_timer_init (&timeout_watcher,timeout_cb,5.5,0); // in document the last is 0. not 0,I don't know why yet
ev_timer_start (loop,&timeout_watcher);

ev_run (loop,0);

return 0;
}
编译(在__INCLUDE目录下)

gcc demo.c -o demo -I./include -L./lib -lev

运行(在__INCLUDE目录下)

cp lib/* /usr/lib

./demo

libuv

git clone https://github.com/libuv/libuv.git
安装glib

No package 'libffi' found

apt-get install libffi-dev

glib

bluez5
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: