diff options
author | Nick Mathewson <nickm@torproject.org> | 2010-02-20 18:44:35 -0500 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2010-02-23 15:20:33 -0500 |
commit | d3288293fdc6aef510cc217b171187aac19c444b (patch) | |
tree | b45eac524f5738d98f35b8e4bedc4a11a1bb20ec /bufferevent_pair.c | |
parent | 38ec0a773b73375410cbb5a4eaeece3d0ab1caa0 (diff) | |
download | libevent-d3288293fdc6aef510cc217b171187aac19c444b.tar.gz |
Provide consistent, tested semantics for bufferevent timeouts
The different bufferevent implementations had different behavior for
their timeouts. Some of them kept re-triggering the timeouts
indefinitely; some disabled the event immediately the first time a
timeout triggered. Some of them made the timeouts only count when
the bufferevent was actively trying to read or write; some did not.
The new behavior is modeled after old socket bufferevents, since
they were here first and their behavior is relatively sane.
Basically, each timeout disables the bufferevent's corresponding
read or write operation when it fires. Timeouts are stopped
whenever we suspend writing or reading, and reset whenever we
unsuspend writing or reading. Calling bufferevent_enable resets a
timeout, as does changing the timeout value.
Diffstat (limited to 'bufferevent_pair.c')
-rw-r--r-- | bufferevent_pair.c | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/bufferevent_pair.c b/bufferevent_pair.c index 32280a6a..1025e7cd 100644 --- a/bufferevent_pair.c +++ b/bufferevent_pair.c @@ -165,14 +165,22 @@ be_pair_transfer(struct bufferevent *src, struct bufferevent *dst, } else { if (!ignore_wm) goto done; + n = evbuffer_get_length(src->output); evbuffer_add_buffer(dst->input, src->output); } } else { + n = evbuffer_get_length(src->output); evbuffer_add_buffer(dst->input, src->output); } - BEV_RESET_GENERIC_READ_TIMEOUT(dst); - BEV_RESET_GENERIC_WRITE_TIMEOUT(dst); + if (n) { + BEV_RESET_GENERIC_READ_TIMEOUT(dst); + + if (evbuffer_get_length(dst->output)) + BEV_RESET_GENERIC_WRITE_TIMEOUT(dst); + else + BEV_DEL_GENERIC_WRITE_TIMEOUT(dst); + } src_size = evbuffer_get_length(src->output); dst_size = evbuffer_get_length(dst->input); @@ -226,8 +234,11 @@ be_pair_enable(struct bufferevent *bufev, short events) incref_and_lock(bufev); - if (_bufferevent_generic_adj_timeouts(bufev) < 0) - return -1; + if (events & EV_READ) { + BEV_RESET_GENERIC_READ_TIMEOUT(bufev); + } + if ((events & EV_WRITE) && evbuffer_get_length(bufev->output)) + BEV_RESET_GENERIC_WRITE_TIMEOUT(bufev); /* We're starting to read! Does the other side have anything to write?*/ if ((events & EV_READ) && partner && @@ -246,7 +257,12 @@ be_pair_enable(struct bufferevent *bufev, short events) static int be_pair_disable(struct bufferevent *bev, short events) { - return _bufferevent_generic_adj_timeouts(bev); + if (events & EV_READ) { + BEV_DEL_GENERIC_READ_TIMEOUT(bev); + } + if (events & EV_WRITE) + BEV_DEL_GENERIC_WRITE_TIMEOUT(bev); + return 0; } static void |