What's New In Libevent 2.0 so far:
1. Meta-issues
1.1. About this document
This document describes the key differences between Libevent 1.4 and
Libevent 2.0, from a user's point of view. It was most recently
updated based on features in git master as of August 2010.
NOTE: I am very sure that I missed some thing on this list. Caveat
haxxor.
1.2. Better documentation
There is now a book-in-progress that explains how to use Libevent and its
growing pile of APIs. As of this writing, it covers everything except the
http and rpc code. Check out the latest draft at
http://www.wangafu.net/~nickm/libevent-book/ .
2. New and Improved Event APIs
Many APIs are improved, refactored, or deprecated in Libevent 2.0.
COMPATIBILITY:
Nearly all existing code that worked with Libevent 1.4 should still
work correctly with Libevent 2.0. However, if you are writing new code,
or if you want to port old code, we strongly recommend using the new APIs
and avoiding deprecated APIs as much as possible.
Binaries linked against Libevent 1.4 will need to be recompiled to link
against Libevent 2.0. This is nothing new; we have never been good at
preserving binary compatibility between releases. We'll try harder in the
future, though: see 2.1 below.
2.1. New header layout for improved forward-compatibility
Libevent 2.0 has a new header layout to make it easier for programmers to
write good, well-supported libevent code. The new headers are divided
into three types.
There are *regular headers*, like event2/event.h. These headers contain
the functions that most programmers will want to use.
There are *backward compatibility headers*, like event2/event_compat.h.
These headers contain declarations for deprecated functions from older
versions of Libevent. Documentation in these headers should suggest what's
wrong with the old functions, and what functions you want to start using
instead of the old ones. Some of these functions might be removed in a
future release. New programs should generally not include these headers.
Finally, there are *structure headers*, like event2/event_struct.h.
These headers contain definitions of some structures that Libevent has
historically exposed. Exposing them caused problems in the past,
since programs that were compiled to work with one version of Libevent
would often stop working with another version that changed the size or
layout of some object. We've moving them into separate headers so
that programmers can know that their code is not depending on any
unstable aspect of the Libvent ABI. New programs should generally not
include these headers unless they really know what they are doing, are
willing to rebuild their software whenever they want to link it
against a new version of Libevent, and are willing to risk their code
breaking if and when data structures change.
Functionality that once was located in event.h is now more subdivided.
The core event logic is now in event2/event.h. The "evbuffer" functions
for low-level buffer manipulation are in event2/buffer.h. The
"bufferevent" functions for higher-level buffered IO are in
event2/bufferevent.h.
COMPATIBILITY:
All of the old headers (event.h, evdns.h, evhttp.h, evrpc.h, and
evutil.h) will continue to work by including the corresponding new
headers. Old code should not be broken by this change.
2.2. New thread-safe, binary-compatible, harder-to-mess-up APIs
Some aspects of the historical Libevent API have encouraged
non-threadsafe code, or forced code built against one version of Libevent
to no longer build with another. The problems with now-deprecated APIs
fell into two categories:
1) Dependence on the "current" event_base. In an application with
multiple event_bases, Libevent previously had a notion of the
"current" event_base. New events were linked to this base, and
the caller needed to explicitly reattach them to another base.
This was horribly error-prone.
Functions like "event_set" that worked with the "current" event_base
are now deprecated but still available (see 2.1). There are new
functions like "event_assign" that take an explicit event_base
argument when setting up a structure. Using these functions will help
prevent errors in your applications, and to be more threadsafe.
2) Structure dependence. Applications needed to allocate 'struct
event' themselves, since there was no function in Libevent to do it
for them. But since the size and contents of struct event can
change between libevent versions, this created binary-compatibility
nightmares. All structures of this kind are now isolated in
_struct.h header (see 2.1), and there are new allocate-and-
initialize functions you can use instead of the old initialize-only
functions. For example, instead of malloc and event_set, you
can use event_new().
(For people who do really want to allocate a struct event on the
stack, or put one inside another structure, you can still use
event2/event_compat.h.)
So in the case where old code would look like this:
#include <event.h>
...
struct event *ev = malloc(sizeof(struct event));
/* This call will cause a buffer overrun if you compile with one version
of Libevent and link dynamically against another. */
event_set(ev, fd, EV_READ, cb, NULL);
/* If you forget this call, your code will break in hard-to-diagnose
ways in the presence of multiple event bases. */
event_set_base(ev, base);
New code will look more like this:
#include <event2/event.h>
...
struct event *ev;
ev = event_new(base, fd, EV_READ, cb, NULL);
2.3. Overrideable allocation functions
If you want to override the allocation functions used by libevent
(for example, to use a specialized allocator, or debug memory
issues, or so on), you can replace them by calling
event_set_mem_functions. It takes replacements for malloc(),
free(), and realloc().
If you're going to use this facility, you need to call it _before_
Libevent does any memory allocation; otherwise, Libevent may allocate some
memory with malloc(), and free it with the free() function you provide.
You can disable this feature when you are building Libevent by passing
the --disable-malloc-replacement argument to configure.
2.4. Configurable event_base creation
Older versions of Libevent would always got the fastest backend
available, unless you reconfigured their behavior with the environment
variables EVENT_NOSELECT, EVENT_NOPOLL, and so forth. This was annoying
to programmers who wanted to pick a backend explicitly without messing
with the environment.
Also, despite our best efforts, not every backend supports every
operation we might like. Some features (like edge-triggered events, or
working with non-socket file descriptors) only work with some operating
systems' fast backends. Previously, programmers who cared about this
needed to know which backends supported what. This tended to get quite
ungainly.
There is now an API to choose backends, either by name or by feature.
Here is an example:
struct event_config_t *config;
struct event_base *base;
/* Create a new configuration object. */
config = event_config_new();
/* We don't want to use the "select" method. */
event_config_avoid_method(config, "select");
/* We want a method that can work with non-socket file descriptors */
event_config_require_features(config, EV_FEATURE_FDS);
base = event_base_new_with_config(config);
if (!base) {
/* There is no backend method that does what we want. */
exit(1);
}
event_config_free(config);
Supported features are documented in event
没有合适的资源?快使用搜索试试~ 我知道了~
libevent.tar.gz的源码包
需积分: 44 17 下载量 172 浏览量
2015-11-30
23:51:41
上传
评论
收藏 835KB GZ 举报
温馨提示
共168个文件
c:69个
h:57个
in:8个
这是一个libevent的源码包,用于事件驱动的案例分析
资源推荐
资源详情
资源评论
收起资源包目录
libevent.tar.gz的源码包 (168个子文件)
configure.ac 22KB
Makefile.am 7KB
Makefile.am 3KB
Makefile.am 1KB
Makefile.am 833B
evdns.c 125KB
http.c 109KB
regress_http.c 95KB
event.c 74KB
buffer.c 72KB
evutil.c 57KB
regress.c 54KB
regress_dns.c 52KB
regress_buffer.c 47KB
bufferevent_openssl.c 37KB
evrpc.c 29KB
regress_util.c 28KB
bufferevent_ratelim.c 28KB
regress.gen.c 27KB
regress_bufferevent.c 22KB
bufferevent.c 22KB
evmap.c 21KB
listener.c 21KB
regress_rpc.c 19KB
bufferevent_async.c 18KB
bufferevent_sock.c 17KB
bufferevent_filter.c 15KB
event_tagging.c 14KB
regress_ssl.c 13KB
arc4random.c 13KB
epoll.c 13KB
regress_thread.c 13KB
test-ratelim.c 13KB
kqueue.c 12KB
signal.c 12KB
evthread.c 12KB
evport.c 12KB
regress_main.c 10KB
tinytest.c 10KB
win32select.c 10KB
http-server.c 10KB
regress_iocp.c 9KB
bufferevent_pair.c 9KB
regress_zlib.c 8KB
buffer_iocp.c 8KB
evthread_win32.c 8KB
select.c 8KB
poll.c 8KB
devpoll.c 8KB
event_iocp.c 7KB
le-proxy.c 7KB
dns-example.c 6KB
regress_testutils.c 6KB
regress_listener.c 6KB
regress_et.c 6KB
test-changelist.c 6KB
bench_httpclient.c 6KB
log.c 5KB
bench_http.c 5KB
evthread_pthread.c 5KB
evutil_rand.c 5KB
bench.c 5KB
bench_cascade.c 4KB
hello-world.c 3KB
test-eof.c 3KB
test-weof.c 3KB
regress_minheap.c 3KB
test-time.c 3KB
event-test.c 3KB
strlcpy.c 2KB
epoll_sub.c 2KB
time-test.c 2KB
test-init.c 2KB
signal-test.c 1KB
ChangeLog 90KB
compile 7KB
configure 494KB
depcomp 20KB
Doxyfile 10KB
config.guess 44KB
tree.h 44KB
event.h 44KB
http.h 32KB
buffer.h 30KB
ht-internal.h 28KB
bufferevent.h 28KB
dns.h 24KB
util.h 22KB
rpc.h 20KB
queue.h 16KB
bufferevent-internal.h 15KB
evthread-internal.h 14KB
event-internal.h 12KB
dns_compat.h 12KB
event-config.h 11KB
evbuffer-internal.h 11KB
util-internal.h 10KB
thread.h 9KB
iocp-internal.h 7KB
event_compat.h 7KB
共 168 条
- 1
- 2
资源评论
sauphy
- 粉丝: 64
- 资源: 22
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功