1、即使上万连接,libevent也能工作得很好
2、event和eventbase是libevent的核心内容,通过bufferevent可以实现对buffer的读和写。
- libevent_core
-
所有的核心event和buffer,包含了所有的event_base,evbuffer,bufferevent,和utility 方法。
libevent_extra
这个库定义了你在实现HTTP,DNS,或RPC应用时可能需要的protocol-specific 方法
- libevent
-
这是历史遗留的版本,不建议使用,包含了所有的libevnet-core和libevent-extra。
- libevent_pthreads
-
这个库实现了基于Pthreads库的多线程库,是从libevent-core的一部分,所以你并不需要同pthread一起连接。
- libevent_openssl
-
这个库支持使用bufferevent和OpenSSL库来实现加密交流。是libevent-core的一部分,所以也不需要单独引用。
3、使用libevent的方法之前,需要实例化一个或多个的event_base结构,每一个event_base结构管理了一系列的event同时可以把event推送到激活队列中去。但这是单线程的,如果你想使用多线程,你可以实例化多个event_base 同时使用实例化相应的线程。
4、event_base_new()方法实例化并返回一个新的默认设置的event_base对象,同时检查环境状态,返回event_base 对象的指针,如果失败返回NULL。
struct event_base *event_base_new(void);
使用event_config_new()来进行更多的设置。struct event_config *event_config_new(void);
struct event_base *event_base_new_with_config(conststruct event_config *cfg);
void event_config_free(struct event_config *cfg);
int event_config_avoid_method(struct event_config *cfg, constchar *method); enum event_method_feature {
EV_FEATURE_ET = 0x01,
EV_FEATURE_O1 = 0x02,
EV_FEATURE_FDS = 0x04,
}; int event_config_require_features(struct event_config *cfg, enum event_method_feature feature); enum event_base_config_flag {
EVENT_BASE_FLAG_NOLOCK = 0x01,
EVENT_BASE_FLAG_IGNORE_ENV = 0x02,
EVENT_BASE_FLAG_STARTUP_IOCP = 0x04,
EVENT_BASE_FLAG_NO_CACHE_TIME = 0x08,
EVENT_BASE_FLAG_EPOLL_USE_CHANGELIST = 0x10,
EVENT_BASE_FLAG_PRECISE_TIMER = 0x20
}; int event_config_set_flag(struct event_config *cfg, enum event_base_config_flag flag);
浙公网安备 33010602011771号