Chinaunix首页 | 论坛 | 博客
  • 博客访问: 157301
  • 博文数量: 35
  • 博客积分: 2011
  • 博客等级: 大尉
  • 技术积分: 345
  • 用 户 组: 普通用户
  • 注册时间: 2009-03-09 21:36
文章存档

2010年(10)

2009年(25)

我的朋友

分类: 网络与安全

2009-03-13 19:36:39

由于honeyd软件依赖与libevent函数库,所以在其很多的事件处理机制上都运用了libevent中的函数,所以要彻底搞懂honeyd还有对libevent有一定的了解,所以阅读了一下libevent官方的说明文档的部分内容,在每一段后还附了我翻译的内容,就是按着我的理解翻译的,如果有不准确的地方还请指点。

libevent is an event notification library for developing scalable network servers. The libevent API provides a mechanism to execute a callback function when a specific event occurs on a file descriptor or after a timeout has been reached. Furthermore, libevent also support callbacks due to signals or regular timeouts.

libevent是一个为了开发可升级的网络服务器的事件触发函数库。libeventAPI提供了一种当一个特定的事件发生在一个文件描述符上或是在一段时间间隔过后来执行一个回调函数的机制。此外,libevent还提供了基于信号或是定时器的回调函数。

libevent is meant to replace the event loop found in event driven network servers. An application just needs to call and then add or remove events dynamically without having to change the event loop. libevent被设计用来替代在事件驱动的网络服务器中的循环事件机制。一个基于libevent的应用程序只需要调用函数,然后在动态地加入或删除时间而并不需要一个循环。

Every program that uses libevent must include the <> header, and pass the -levent flag to the linker. Before using any of the functions in the library, you must call or to perform one-time initialization of the libevent library.

每一个使用libevent的程序都必须包含头文件<>,而且在编译的时候还要把参数-levent传给连接器。在调用任何libevent库函数之前,你必须调用 or 来初始化。

For each file descriptor that you wish to monitor, you must declare an event structure and call to initialize the members of the structure. To enable notification, you add the structure to the list of monitored events by calling . The event structure must remain allocated as long as it is active, so it should be allocated on the heap. Finally, you call to loop and dispatch events.

对于任何一个你希望监视的文件描述符,你都必须声明一个事件结构体并且调用来初始化这个结构体中的成员。如果想要开启这个监视,你还需要调用函数把这个结构体加入到事件的监视列表中。这个事件结构体在它的活跃期间必须始终驻留在内存中,所以它应该被放在堆中。最后,你调用来循环和分配事件。

 

阅读(2233) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~