diff options
author | Nick Mathewson <nickm@torproject.org> | 2009-05-19 21:39:35 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2009-05-19 21:39:35 +0000 |
commit | 23243b8a985e26e19deafd81e58159d545a31f34 (patch) | |
tree | 8de7f3893afdb9465bc0030a8292525bf524a82b /test/regress_zlib.c | |
parent | ed1bbc7a9f41be00607b3f56933378a625838d6a (diff) | |
download | libevent-23243b8a985e26e19deafd81e58159d545a31f34.tar.gz |
Replace reserve/commit with new iovec-based interface. Add a new evbuffer_peek.
svn:r1296
Diffstat (limited to 'test/regress_zlib.c')
-rw-r--r-- | test/regress_zlib.c | 55 |
1 files changed, 37 insertions, 18 deletions
diff --git a/test/regress_zlib.c b/test/regress_zlib.c index 3f356fe1..d171b587 100644 --- a/test/regress_zlib.c +++ b/test/regress_zlib.c @@ -106,28 +106,38 @@ static enum bufferevent_filter_result zlib_input_filter(struct evbuffer *src, struct evbuffer *dst, ssize_t lim, enum bufferevent_flush_mode state, void *ctx) { + struct evbuffer_iovec v_in[1]; + struct evbuffer_iovec v_out[1]; int nread, nwrite; - int res; + int res, n; z_streamp p = ctx; do { /* let's do some decompression */ - p->avail_in = evbuffer_get_contiguous_space(src); - p->next_in = evbuffer_pullup(src, p->avail_in); + n = evbuffer_peek(src, -1, NULL, v_in, 1); + if (n) { + p->avail_in = v_in[0].iov_len; + p->next_in = v_in[0].iov_base; + } else { + p->avail_in = 0; + p->next_in = 0; + } - p->next_out = evbuffer_reserve_space(dst, 4096); - p->avail_out = 4096; + evbuffer_reserve_space(dst, 4096, v_out, 1); + p->next_out = v_out[0].iov_base; + p->avail_out = v_out[0].iov_len; /* we need to flush zlib if we got a flush */ res = inflate(p, getstate(state)); /* let's figure out how much was compressed */ - nread = evbuffer_get_contiguous_space(src) - p->avail_in; - nwrite = 4096 - p->avail_out; + nread = v_in[0].iov_len - p->avail_in; + nwrite = v_out[0].iov_len - p->avail_out; evbuffer_drain(src, nread); - evbuffer_commit_space(dst, nwrite); + v_out[0].iov_len = nwrite; + evbuffer_commit_space(dst, v_out, 1); if (res==Z_BUF_ERROR) { /* We're out of space, or out of decodeable input. @@ -150,29 +160,38 @@ static enum bufferevent_filter_result zlib_output_filter(struct evbuffer *src, struct evbuffer *dst, ssize_t lim, enum bufferevent_flush_mode state, void *ctx) { + struct evbuffer_iovec v_in[1]; + struct evbuffer_iovec v_out[1]; int nread, nwrite; - int res; + int res, n; z_streamp p = ctx; do { /* let's do some compression */ - p->avail_in = evbuffer_get_contiguous_space(src); - p->next_in = evbuffer_pullup(src, p->avail_in); - - p->next_out = evbuffer_reserve_space(dst, 4096); - p->avail_out = 4096; + n = evbuffer_peek(src, -1, NULL, v_in, 1); + if (n) { + p->avail_in = v_in[0].iov_len; + p->next_in = v_in[0].iov_base; + } else { + p->avail_in = 0; + p->next_in = 0; + } + evbuffer_reserve_space(dst, 4096, v_out, 1); + p->next_out = v_out[0].iov_base; + p->avail_out = v_out[0].iov_len; /* we need to flush zlib if we got a flush */ res = deflate(p, getstate(state)); - /* let's figure out how much was compressed */ - nread = evbuffer_get_contiguous_space(src) - p->avail_in; - nwrite = 4096 - p->avail_out; + /* let's figure out how much was decompressed */ + nread = v_in[0].iov_len - p->avail_in; + nwrite = v_out[0].iov_len - p->avail_out; evbuffer_drain(src, nread); - evbuffer_commit_space(dst, nwrite); + v_out[0].iov_len = nwrite; + evbuffer_commit_space(dst, v_out, 1); if (res==Z_BUF_ERROR) { /* We're out of space, or out of decodeable input. |