linux 事件循环,libuEv - Linux的轻量级事件循环库

libuEv | Simple event loop for Linux

fb2c4935c66c921d32498633d9715a23.png68747470733a2f2f7363616e2e636f7665726974792e636f6d2f70726f6a656374732f333834362f62616467652e737667

NOTE: Incompatible failure mode changes in v2.0 compared to v1.x!

Introduction

libuEv is a simple event loop in the style of the more established libevent, libev and the venerable Xt(3) event loop. The u (micro) in the name refers to both the small feature set and the small size overhead impact of the library.

Failure mode changes introduced in v2.0 may affect users of v1.x, See the ChangeLog for the full details.

The API documentation is available as a separate document.

Example

Notice below how watcher UEV_ERROR conditions must be handled by each callback. I/O watchers must also check for UEV_HUP. Both errors are usually fatal, libuEv makes sure to stop each watcher before a callback runs, leaving it up to the callback to take appropriate action.

#include

#include

static void cb(uev_t *w, void *arg, int events)

{

if (UEV_ERROR == events) {

puts("Problem with timer, attempting to restart.");

uev_timer_start(w);

}

puts("Every other second");

}

int main(void)

{

uev_t timer;

uev_ctx_t ctx;

uev_init(&ctx);

/* Set up a timer watcher to call cb() every other second */

uev_timer_init(&ctx, &timer, cb, NULL, 2 * 1000, 2 * 1000);

return uev_run(&ctx, 0);

}

Build & Install

libuEv use the GNU configure and build system. To try out the bundled examples, use the --enable-examples switch to the configure script. There is also a limited unit test suite that can be useful to learn how the library works.

./configure

make -j5

make test

sudo make install-strip

sudo ldconfig

The resulting .so file is ~14 kiB.

Origin & References

libuEv originates from LibUEvent by Flemming Madsen, but with a rewritten and much cleaner API. It is now more similar to the famous libev by Mark Lehmann. Another library inspiring this project is picoev by Oku Kazuho.

libuEv is developed and maintained by Joachim Nilsson. It is built for and developed on GNU/Linux systems, patches to support *BSD and its kqueue interface are most welcome.

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值