上述操作event_config的函数在乐成时都返回 0, -1 失败时。
注意设置一个需要后端的event_config很轻易,您的 操作系统不提供。例如,从 Libevent 2.0.1-alpha 开始,没有 O(1) 用于 Windows 的后端,而 Linux 上没有同时提供这两种功能的后端 EV_FEATURE_FDS和EV_FEATURE_O1。假如您已进行配置 Libevent 无法满足,event_base_new_with_config() 将返回 NULL。接口
int event_config_set_num_cpus_hint(struct event_config *cfg, int cpus)
复制代码
不过,此函数现在仅在使用 IOCP 时对 Windows 有用 将来它大概会对其他平台有用。调用它告诉 event_config,它产生的event_base应该只管好好利用 多线程时给定数量的 CPU。请注意,这只是一个提示: 事件库最终使用的 CPU 大概比您选择的更多或更少。
接口
int event_config_set_max_dispatch_interval(struct event_config *cfg,
const struct timeval *max_interval, int max_callbacks,
int min_priority);
复制代码
此函数通过限制低优先级的数量来防止优先级倒置 在查抄更多高优先级事件之前,可以调用事件回调。 假如 max_interval 为非 null,则事件循环会查抄每个事件之后的时间 回调,假如已通过,则重新扫描高优先级事件max_interval。 假如max_callbacks为非负数,则事件循环还会查抄更多事件 调用max_callbacks回调后。这些规则适用于任何 min_priority 或更高的事件。
示例:首选边缘触发的后端
[code]struct event_config *cfg;struct event_base *base;int i;/* My program wants to use edge-triggered events if at all possible. So I'll try to get a base twice: Once insisting on edge-triggered IO, and once not. */for (i=0; i