Permalink
Browse files

Update levent. It has some major changes Pincaster may take advantage…

… of.
  • Loading branch information...
1 parent ae76835 commit 911ef73cd583ef3d51bbc97b239a6299074932e4 @jedisct1 committed Oct 17, 2010
Showing with 833 additions and 310 deletions.
  1. +4 −3 src/levent2/Makefile.am
  2. +2 −2 src/levent2/WIN32-Code/event2/event-config.h
  3. +3 −2 src/levent2/arc4random.c
  4. +19 −8 src/levent2/buffer.c
  5. +2 −2 src/levent2/buffer_iocp.c
  6. +12 −7 src/levent2/bufferevent-internal.h
  7. +4 −4 src/levent2/bufferevent.c
  8. +2 −2 src/levent2/bufferevent_async.c
  9. +24 −6 src/levent2/bufferevent_filter.c
  10. +25 −25 src/levent2/bufferevent_openssl.c
  11. +53 −25 src/levent2/bufferevent_ratelim.c
  12. +3 −3 src/levent2/configure.in
  13. +0 −3 src/levent2/devpoll.c
  14. +15 −9 src/levent2/epoll.c
  15. +8 −6 src/levent2/evdns.c
  16. +0 −2 src/levent2/event-internal.h
  17. +12 −6 src/levent2/event.c
  18. +7 −5 src/levent2/event_tagging.c
  19. +0 −3 src/levent2/evport.c
  20. +13 −3 src/levent2/evsignal-internal.h
  21. +23 −5 src/levent2/evutil.c
  22. +7 −4 src/levent2/http.c
  23. +15 −0 src/levent2/include/event2/listener.h
  24. +3 −2 src/levent2/kqueue.c
  25. +217 −37 src/levent2/listener.c
  26. +1 −1 src/levent2/log-internal.h
  27. +1 −1 src/levent2/minheap-internal.h
  28. +0 −3 src/levent2/poll.c
  29. +6 −6 src/levent2/select.c
  30. +123 −41 src/levent2/signal.c
  31. +1 −1 src/levent2/test/bench.c
  32. +1 −1 src/levent2/test/bench_http.c
  33. +10 −2 src/levent2/test/bench_httpclient.c
  34. +11 −6 src/levent2/test/regress.c
  35. +2 −2 src/levent2/test/regress_buffer.c
  36. +3 −3 src/levent2/test/regress_bufferevent.c
  37. +15 −14 src/levent2/test/regress_http.c
  38. +1 −1 src/levent2/test/regress_iocp.c
  39. +60 −0 src/levent2/test/regress_listener.c
  40. +1 −1 src/levent2/test/regress_main.c
  41. +1 −1 src/levent2/test/regress_rpc.c
  42. +76 −42 src/levent2/test/regress_ssl.c
  43. +19 −0 src/levent2/test/regress_util.c
  44. +1 −1 src/levent2/test/regress_zlib.c
  45. +4 −3 src/levent2/test/tinytest.c
  46. +21 −0 src/levent2/util-internal.h
  47. +2 −6 src/levent2/win32select.c
@@ -33,7 +33,7 @@ RELEASE = -release 2.0
# Return (current+1:0:0)
#
# Once an RC is out, DO NOT MAKE ANY ABI-BREAKING CHANGES IN THAT SERIES.
-VERSION_INFO = 3:0:1
+VERSION_INFO = 4:0:2
# History: RELEASE VERSION_INFO
# 2.0.1-alpha -- 2.0 1:0:0
@@ -42,9 +42,10 @@ VERSION_INFO = 3:0:1
# 2.0.4-alpha -- 3:0:0
# 2.0.5-beta -- 4:0:0
# 2.0.6-rc -- 2.0 2:0:0
-# 2.0.7-rc -- 2.0 3:0:1
+# 2.0.7-rc -- 2.0 3:0:1
+# 2.0.8-rc -- 2.0 4:0:2
# Planned:
-# 2.0.8-stable -- 2.0 3:1:1 (Assuming no ABI change)
+# 2.0.9-stable-- 2.0 4:1:2 (Assuming no ABI change)
#
# If Libevent 2.1.1 makes 'struct event' etc opaque in the headers:
# 2.1.1-alpha -- 2.1 1:0:0
@@ -274,7 +274,7 @@
/* #undef _EVENT_HAVE_WORKING_KQUEUE */
/* Numeric representation of the version */
-#define _EVENT_NUMERIC_VERSION 0x02000701
+#define _EVENT_NUMERIC_VERSION 0x02000801
/* Name of package */
#define _EVENT_PACKAGE "libevent"
@@ -324,7 +324,7 @@
#define _EVENT_TIME_WITH_SYS_TIME 1
/* Version number of package */
-#define _EVENT_VERSION "2.0.7-rc-dev"
+#define _EVENT_VERSION "2.0.8-rc-dev"
/* Define to appropriate substitue if compiler doesnt have __func__ */
#define _EVENT___func__ __FUNCTION__
@@ -179,7 +179,8 @@ arc4_seed_sysctl_linux(void)
int mib[] = { CTL_KERN, KERN_RANDOM, RANDOM_UUID };
unsigned char buf[ADD_ENTROPY];
size_t len, n;
- int i, any_set;
+ unsigned i;
+ int any_set;
memset(buf, 0, sizeof(buf));
@@ -190,7 +191,7 @@ arc4_seed_sysctl_linux(void)
return -1;
}
/* make sure that the buffer actually got set. */
- for (i=any_set=0; i<sizeof(buf); ++i) {
+ for (i=0,any_set=0; i<sizeof(buf); ++i) {
any_set |= buf[i];
}
if (!any_set)
View
@@ -74,6 +74,7 @@
#ifdef _EVENT_HAVE_UNISTD_H
#include <unistd.h>
#endif
+#include <limits.h>
#include "event2/event.h"
#include "event2/buffer.h"
@@ -570,7 +571,7 @@ evbuffer_reserve_space(struct evbuffer *buf, ev_ssize_t size,
vec[0].iov_base = CHAIN_SPACE_PTR(chain);
vec[0].iov_len = CHAIN_SPACE_LEN(chain);
- EVUTIL_ASSERT(vec[0].iov_len >= size);
+ EVUTIL_ASSERT(size<0 || (size_t)vec[0].iov_len >= (size_t)size);
n = 1;
} else {
if (_evbuffer_expand_fast(buf, size, n_vecs)<0)
@@ -621,7 +622,7 @@ evbuffer_commit_space(struct evbuffer *buf,
(buf->last && vec[0].iov_base == (void*)CHAIN_SPACE_PTR(buf->last))) {
/* The user only got or used one chain; it might not
* be the first one with space in it. */
- if (vec[0].iov_len > CHAIN_SPACE_LEN(buf->last))
+ if ((size_t)vec[0].iov_len > (size_t)CHAIN_SPACE_LEN(buf->last))
goto done;
buf->last->off += vec[0].iov_len;
added = vec[0].iov_len;
@@ -645,7 +646,7 @@ evbuffer_commit_space(struct evbuffer *buf,
if (!chain)
goto done;
if (vec[i].iov_base != (void*)CHAIN_SPACE_PTR(chain) ||
- vec[i].iov_len > CHAIN_SPACE_LEN(chain))
+ (size_t)vec[i].iov_len > CHAIN_SPACE_LEN(chain))
goto done;
chain = chain->next;
}
@@ -1884,7 +1885,17 @@ evbuffer_expand(struct evbuffer *buf, size_t datlen)
#ifdef _EVENT_HAVE_SYS_UIO_H
/* number of iovec we use for writev, fragmentation is going to determine
* how much we end up writing */
-#define NUM_WRITE_IOVEC 128
+
+#define DEFAULT_WRITE_IOVEC 128
+
+#if defined(UIO_MAXIOV) && UIO_MAXIOV < DEFAULT_WRITE_IOVEC
+#define NUM_WRITE_IOVEC UIO_MAXIOV
+#elif defined(IOV_MAX) && IOV_MAX < DEFAULT_WRITE_IOVEC
+#define NUM_WRITE_IOVEC IOV_MAX
+#else
+#define NUM_WRITE_IOVEC DEFAULT_WRITE_IOVEC
+#endif
+
#define IOV_TYPE struct iovec
#define IOV_PTR_FIELD iov_base
#define IOV_LEN_FIELD iov_len
@@ -1934,7 +1945,7 @@ _evbuffer_read_setup_vecs(struct evbuffer *buf, ev_ssize_t howmuch,
}
chain = *firstchainp;
- for (i = 0; i < n_vecs_avail && so_far < howmuch; ++i) {
+ for (i = 0; i < n_vecs_avail && so_far < (size_t)howmuch; ++i) {
size_t avail = CHAIN_SPACE_LEN(chain);
if (avail > (howmuch - so_far) && exact)
avail = howmuch - so_far;
@@ -2252,7 +2263,7 @@ evbuffer_write_atmost(struct evbuffer *buffer, evutil_socket_t fd,
goto done;
}
- if (howmuch < 0 || howmuch > buffer->total_len)
+ if (howmuch < 0 || (size_t)howmuch > buffer->total_len)
howmuch = buffer->total_len;
if (howmuch > 0) {
@@ -2420,7 +2431,7 @@ evbuffer_search_range(struct evbuffer *buffer, const char *what, size_t len, con
if (end)
last_chain = end->_internal.chain;
- if (!len)
+ if (!len || len > EV_SSIZE_MAX)
goto done;
first = what[0];
@@ -2435,7 +2446,7 @@ evbuffer_search_range(struct evbuffer *buffer, const char *what, size_t len, con
pos.pos += p - start_at;
pos._internal.pos_in_chain += p - start_at;
if (!evbuffer_ptr_memcmp(buffer, &pos, what, len)) {
- if (end && pos.pos + len > end->pos)
+ if (end && pos.pos + (ev_ssize_t)len > end->pos)
goto not_found;
else
goto done;
@@ -110,7 +110,7 @@ evbuffer_commit_read(struct evbuffer *evbuf, ev_ssize_t nBytes)
if (!((*chainp)->flags & EVBUFFER_MEM_PINNED_R))
chainp = &(*chainp)->next;
remaining = nBytes;
- for (i = 0; remaining > 0 && i < buf->n_buffers; ++i) {
+ for (i = 0; remaining > 0 && i < (unsigned)buf->n_buffers; ++i) {
EVUTIL_ASSERT(*chainp);
len = buf->buffers[i].len;
if (remaining < len)
@@ -197,7 +197,7 @@ evbuffer_launch_write(struct evbuffer *buf, ev_ssize_t at_most,
for (i=0; i < MAX_WSABUFS && chain; ++i, chain=chain->next) {
WSABUF *b = &buf_o->buffers[i];
- b->buf = chain->buffer + chain->misalign;
+ b->buf = (char*)( chain->buffer + chain->misalign );
_evbuffer_chain_pin(chain, EVBUFFER_MEM_PINNED_W);
if ((size_t)at_most > chain->off) {
@@ -56,6 +56,11 @@ extern "C" {
/* On a socket bufferevent: can't do any operations while we're waiting for
* name lookup to finish. */
#define BEV_SUSPEND_LOOKUP 0x08
+/* On a base bufferevent, for reading: used when a filter has choked this
+ * (underlying) bufferevent because it has stopped reading from it. */
+#define BEV_SUSPEND_FILT_READ 0x10
+
+typedef ev_uint16_t bufferevent_suspend_flags;
struct bufferevent_rate_limit_group {
/** List of all members in the group */
@@ -91,7 +96,7 @@ struct bufferevent_rate_limit_group {
/** The smallest number of bytes that any member of the group should
* be limited to read or write at a time. */
- ev_uint32_t min_share;
+ ev_int32_t min_share;
/** Timeout event that goes off once a tick, when the bucket is ready
* to refill. */
struct event master_refill_event;
@@ -154,12 +159,12 @@ struct bufferevent_private {
/** If set, read is suspended until one or more conditions are over.
* The actual value here is a bitfield of those conditions; see the
* BEV_SUSPEND_* flags above. */
- short read_suspended;
+ bufferevent_suspend_flags read_suspended;
/** If set, writing is suspended until one or more conditions are over.
* The actual value here is a bitfield of those conditions; see the
* BEV_SUSPEND_* flags above. */
- short write_suspended;
+ bufferevent_suspend_flags write_suspended;
/** Set to the current socket errno if we have deferred callbacks and
* an events callback is pending. */
@@ -265,17 +270,17 @@ int bufferevent_init_common(struct bufferevent_private *, struct event_base *, c
/** For internal use: temporarily stop all reads on bufev, until the conditions
* in 'what' are over. */
-void bufferevent_suspend_read(struct bufferevent *bufev, short what);
+void bufferevent_suspend_read(struct bufferevent *bufev, bufferevent_suspend_flags what);
/** For internal use: clear the conditions 'what' on bufev, and re-enable
* reading if there are no conditions left. */
-void bufferevent_unsuspend_read(struct bufferevent *bufev, short what);
+void bufferevent_unsuspend_read(struct bufferevent *bufev, bufferevent_suspend_flags what);
/** For internal use: temporarily stop all writes on bufev, until the conditions
* in 'what' are over. */
-void bufferevent_suspend_write(struct bufferevent *bufev, short what);
+void bufferevent_suspend_write(struct bufferevent *bufev, bufferevent_suspend_flags what);
/** For internal use: clear the conditions 'what' on bufev, and re-enable
* writing if there are no conditions left. */
-void bufferevent_unsuspend_write(struct bufferevent *bufev, short what);
+void bufferevent_unsuspend_write(struct bufferevent *bufev, bufferevent_suspend_flags what);
#define bufferevent_wm_suspend_read(b) \
bufferevent_suspend_read((b), BEV_SUSPEND_WM)
@@ -60,7 +60,7 @@
#include "util-internal.h"
void
-bufferevent_suspend_read(struct bufferevent *bufev, short what)
+bufferevent_suspend_read(struct bufferevent *bufev, bufferevent_suspend_flags what)
{
struct bufferevent_private *bufev_private =
EVUTIL_UPCAST(bufev, struct bufferevent_private, bev);
@@ -72,7 +72,7 @@ bufferevent_suspend_read(struct bufferevent *bufev, short what)
}
void
-bufferevent_unsuspend_read(struct bufferevent *bufev, short what)
+bufferevent_unsuspend_read(struct bufferevent *bufev, bufferevent_suspend_flags what)
{
struct bufferevent_private *bufev_private =
EVUTIL_UPCAST(bufev, struct bufferevent_private, bev);
@@ -84,7 +84,7 @@ bufferevent_unsuspend_read(struct bufferevent *bufev, short what)
}
void
-bufferevent_suspend_write(struct bufferevent *bufev, short what)
+bufferevent_suspend_write(struct bufferevent *bufev, bufferevent_suspend_flags what)
{
struct bufferevent_private *bufev_private =
EVUTIL_UPCAST(bufev, struct bufferevent_private, bev);
@@ -96,7 +96,7 @@ bufferevent_suspend_write(struct bufferevent *bufev, short what)
}
void
-bufferevent_unsuspend_write(struct bufferevent *bufev, short what)
+bufferevent_unsuspend_write(struct bufferevent *bufev, bufferevent_suspend_flags what)
{
struct bufferevent_private *bufev_private =
EVUTIL_UPCAST(bufev, struct bufferevent_private, bev);
@@ -195,7 +195,7 @@ bev_async_consider_writing(struct bufferevent_async *beva)
/* XXXX This over-commits. */
limit = _bufferevent_get_write_max(&beva->bev);
- if (at_most >= limit)
+ if (at_most >= (size_t)limit && limit >= 0)
at_most = limit;
if (beva->bev.write_suspended) {
@@ -249,7 +249,7 @@ bev_async_consider_reading(struct bufferevent_async *beva)
/* XXXX This over-commits. */
limit = _bufferevent_get_read_max(&beva->bev);
- if (at_most >= limit)
+ if (at_most >= (size_t)limit && limit >= 0)
at_most = limit;
if (beva->bev.read_suspended) {
@@ -168,6 +168,9 @@ bufferevent_filter_new(struct bufferevent *underlying,
struct bufferevent_filtered *bufev_f;
int tmp_options = options & ~BEV_OPT_THREADSAFE;
+ if (!underlying)
+ return NULL;
+
if (!input_filter)
input_filter = be_null_filter;
if (!output_filter)
@@ -202,6 +205,9 @@ bufferevent_filter_new(struct bufferevent *underlying,
_bufferevent_init_generic_timeout_cbs(downcast(bufev_f));
bufferevent_incref(underlying);
+ bufferevent_enable(underlying, EV_READ|EV_WRITE);
+ bufferevent_suspend_read(underlying, BEV_SUSPEND_FILT_READ);
+
return downcast(bufev_f);
}
@@ -225,6 +231,11 @@ be_filter_destruct(struct bufferevent *bev)
} else {
bufferevent_free(bevf->underlying);
}
+ } else {
+ if (bevf->underlying) {
+ bufferevent_unsuspend_read(bevf->underlying,
+ BEV_SUSPEND_FILT_READ);
+ }
}
_bufferevent_del_generic_timeout_cbs(bev);
@@ -234,22 +245,29 @@ static int
be_filter_enable(struct bufferevent *bev, short event)
{
struct bufferevent_filtered *bevf = upcast(bev);
- if (event & EV_READ)
- BEV_RESET_GENERIC_READ_TIMEOUT(bev);
if (event & EV_WRITE)
BEV_RESET_GENERIC_WRITE_TIMEOUT(bev);
- return bufferevent_enable(bevf->underlying, event);
+
+ if (event & EV_READ) {
+ BEV_RESET_GENERIC_READ_TIMEOUT(bev);
+ bufferevent_unsuspend_read(bevf->underlying,
+ BEV_SUSPEND_FILT_READ);
+ }
+ return 0;
}
static int
be_filter_disable(struct bufferevent *bev, short event)
{
struct bufferevent_filtered *bevf = upcast(bev);
- if (event & EV_READ)
- BEV_DEL_GENERIC_READ_TIMEOUT(bev);
if (event & EV_WRITE)
BEV_DEL_GENERIC_WRITE_TIMEOUT(bev);
- return bufferevent_disable(bevf->underlying, event);
+ if (event & EV_READ) {
+ BEV_DEL_GENERIC_READ_TIMEOUT(bev);
+ bufferevent_suspend_read(bevf->underlying,
+ BEV_SUSPEND_FILT_READ);
+ }
+ return 0;
}
static enum bufferevent_filter_result
Oops, something went wrong. Retry.

0 comments on commit 911ef73

Please sign in to comment.