Actually stop using EVBUFFER_LENGTH/DATA, and move them to buffer_compat.h

svn:r1183
This commit is contained in:
Nick Mathewson 2009-04-17 06:56:09 +00:00
parent 796ba15fc6
commit a8f6d961eb
14 changed files with 92 additions and 91 deletions

View File

@ -2259,7 +2259,7 @@ void
evbuffer_cb_suspend(struct evbuffer *buffer, struct evbuffer_cb_entry *cb)
{
if (!(cb->flags & EVBUFFER_CB_SUSPENDED)) {
cb->size_before_suspend = EVBUFFER_LENGTH(buffer);
cb->size_before_suspend = evbuffer_get_length(buffer);
cb->flags |= EVBUFFER_CB_SUSPENDED;
}
}
@ -2274,7 +2274,7 @@ evbuffer_cb_unsuspend(struct evbuffer *buffer, struct evbuffer_cb_entry *cb)
EVBUFFER_CB_CALL_ON_UNSUSPEND);
cb->size_before_suspend = 0;
if (call && (cb->flags & EVBUFFER_CB_ENABLED)) {
cb->cb(buffer, sz, EVBUFFER_LENGTH(buffer), cb->cbarg);
cb->cb(buffer, sz, evbuffer_get_length(buffer), cb->cbarg);
}
}
}

View File

@ -337,9 +337,9 @@ bufferevent_setwatermark(struct bufferevent *bufev, short events,
bufev_private->read_watermarks_cb,
EVBUFFER_CB_ENABLED);
if (EVBUFFER_LENGTH(bufev->input) > highmark)
if (evbuffer_get_length(bufev->input) > highmark)
bufferevent_wm_suspend_read(bufev);
else if (EVBUFFER_LENGTH(bufev->input) < highmark)
else if (evbuffer_get_length(bufev->input) < highmark)
bufferevent_wm_unsuspend_read(bufev);
} else {
/* There is now no high-water mark for read. */

View File

@ -133,7 +133,7 @@ be_underlying_writebuf_full(struct bufferevent_filtered *bevf,
struct bufferevent *u = bevf->underlying;
return state == BEV_NORMAL &&
u->wm_write.high &&
EVBUFFER_LENGTH(u->output) >= u->wm_write.high;
evbuffer_get_length(u->output) >= u->wm_write.high;
}
/** Return 1 if our input buffer is at or over its high watermark such that we
@ -145,7 +145,7 @@ be_readbuf_full(struct bufferevent_filtered *bevf,
struct bufferevent *bufev = downcast(bevf);
return state == BEV_NORMAL &&
bufev->wm_read.high &&
EVBUFFER_LENGTH(bufev->input) >= bufev->wm_read.high;
evbuffer_get_length(bufev->input) >= bufev->wm_read.high;
}
@ -270,7 +270,7 @@ be_filter_process_input(struct bufferevent_filtered *bevf,
ssize_t limit = -1;
if (state == BEV_NORMAL && bev->wm_read.high)
limit = bev->wm_read.high -
EVBUFFER_LENGTH(bev->input);
evbuffer_get_length(bev->input);
res = bevf->process_in(bevf->underlying->input,
bev->input, limit, state, bevf->context);
@ -279,7 +279,7 @@ be_filter_process_input(struct bufferevent_filtered *bevf,
*processed_out = 1;
} while (res == BEV_OK &&
(bev->enabled & EV_READ) &&
EVBUFFER_LENGTH(bevf->underlying->input) &&
evbuffer_get_length(bevf->underlying->input) &&
!be_readbuf_full(bevf, state));
return res;
@ -303,7 +303,7 @@ be_filter_process_output(struct bufferevent_filtered *bevf,
* call the filter no matter what. */
if (!(bufev->enabled & EV_WRITE) ||
be_underlying_writebuf_full(bevf, state) ||
!EVBUFFER_LENGTH(bufev->output))
!evbuffer_get_length(bufev->output))
return BEV_OK;
}
@ -320,7 +320,7 @@ be_filter_process_output(struct bufferevent_filtered *bevf,
if (state == BEV_NORMAL &&
bevf->underlying->wm_write.high)
limit = bevf->underlying->wm_write.high -
EVBUFFER_LENGTH(bevf->underlying->output);
evbuffer_get_length(bevf->underlying->output);
res = bevf->process_out(downcast(bevf)->output,
bevf->underlying->output,
@ -336,18 +336,18 @@ be_filter_process_output(struct bufferevent_filtered *bevf,
(bufev->enabled & EV_WRITE) &&
/* Of if we have nothing more to write and we are
* not flushing. */
EVBUFFER_LENGTH(bufev->output) &&
evbuffer_get_length(bufev->output) &&
/* Or if we have filled the underlying output buffer. */
!be_underlying_writebuf_full(bevf,state));
if (processed && bufev->writecb &&
EVBUFFER_LENGTH(bufev->output) <= bufev->wm_write.low) {
evbuffer_get_length(bufev->output) <= bufev->wm_write.low) {
/* call the write callback.*/
(*bufev->writecb)(bufev, bufev->cbarg);
if (res == BEV_OK &&
(bufev->enabled & EV_WRITE) &&
EVBUFFER_LENGTH(bufev->output) &&
evbuffer_get_length(bufev->output) &&
!be_underlying_writebuf_full(bevf, state)) {
again = 1;
}
@ -394,7 +394,7 @@ be_filter_readcb(struct bufferevent *underlying, void *_me)
res = be_filter_process_input(bevf, state, &processed_any);
if (processed_any &&
EVBUFFER_LENGTH(bufev->input) >= bufev->wm_read.low &&
evbuffer_get_length(bufev->input) >= bufev->wm_read.low &&
bufev->readcb != NULL)
(*bufev->readcb)(bufev, bufev->cbarg);
}

View File

@ -126,7 +126,7 @@ bufferevent_readcb(evutil_socket_t fd, short event, void *arg)
* read more data than would make us reach the watermark.
*/
if (bufev->wm_read.high != 0) {
howmuch = bufev->wm_read.high - EVBUFFER_LENGTH(input);
howmuch = bufev->wm_read.high - evbuffer_get_length(input);
/* we somehow lowered the watermark, stop reading */
if (howmuch <= 0) {
bufferevent_wm_suspend_read(bufev);
@ -154,7 +154,7 @@ bufferevent_readcb(evutil_socket_t fd, short event, void *arg)
/* Invoke the user callback - must always be called last */
if (EVBUFFER_LENGTH(input) >= bufev->wm_read.low &&
if (evbuffer_get_length(input) >= bufev->wm_read.low &&
bufev->readcb != NULL)
(*bufev->readcb)(bufev, bufev->cbarg);
@ -181,7 +181,7 @@ bufferevent_writecb(evutil_socket_t fd, short event, void *arg)
goto error;
}
if (EVBUFFER_LENGTH(bufev->output)) {
if (evbuffer_get_length(bufev->output)) {
evbuffer_unfreeze(bufev->output, 1);
res = evbuffer_write(bufev->output, fd);
evbuffer_freeze(bufev->output, 1);
@ -198,7 +198,7 @@ bufferevent_writecb(evutil_socket_t fd, short event, void *arg)
goto error;
}
if (EVBUFFER_LENGTH(bufev->output) == 0)
if (evbuffer_get_length(bufev->output) == 0)
event_del(&bufev->ev_write);
/*
@ -206,13 +206,13 @@ bufferevent_writecb(evutil_socket_t fd, short event, void *arg)
* low watermark.
*/
if (bufev->writecb != NULL &&
EVBUFFER_LENGTH(bufev->output) <= bufev->wm_write.low)
evbuffer_get_length(bufev->output) <= bufev->wm_write.low)
(*bufev->writecb)(bufev, bufev->cbarg);
return;
reschedule:
if (EVBUFFER_LENGTH(bufev->output) == 0)
if (evbuffer_get_length(bufev->output) == 0)
event_del(&bufev->ev_write);
return;

View File

@ -221,7 +221,7 @@ int evtag_unmarshal_%(name)s(struct evbuffer *, ev_uint32_t,
' struct evbuffer *evbuf)\n'
'{\n'
' ev_uint32_t tag;\n'
' while (EVBUFFER_LENGTH(evbuf) > 0) {\n'
' while (evbuffer_get_length(evbuf) > 0) {\n'
' if (evtag_peek(evbuf, &tag) == -1)\n'
' return (-1);\n'
' switch (tag) {\n'
@ -977,7 +977,7 @@ class EntryVarBytes(Entry):
code = ['if (evtag_payload_length(%(buf)s, &%(varlen)s) == -1)',
' return (-1);',
# We do not want DoS opportunities
'if (%(varlen)s > EVBUFFER_LENGTH(%(buf)s))',
'if (%(varlen)s > evbuffer_get_length(%(buf)s))',
' return (-1);',
'if ((%(var)s = malloc(%(varlen)s)) == NULL)',
' return (-1);',

View File

@ -169,7 +169,7 @@ static int
decode_tag_internal(ev_uint32_t *ptag, struct evbuffer *evbuf, int dodrain)
{
ev_uint32_t number = 0;
int len = EVBUFFER_LENGTH(evbuf);
int len = evbuffer_get_length(evbuf);
ev_uint8_t *data;
int count = 0, shift = 0, done = 0;
@ -229,7 +229,7 @@ evtag_marshal_buffer(struct evbuffer *evbuf, ev_uint32_t tag,
struct evbuffer *data)
{
evtag_encode_tag(evbuf, tag);
encode_int(evbuf, EVBUFFER_LENGTH(data));
encode_int(evbuf, evbuffer_get_length(data));
evbuffer_add_buffer(evbuf, data);
}
@ -275,7 +275,7 @@ evtag_marshal_timeval(struct evbuffer *evbuf, ev_uint32_t tag, struct timeval *t
#define DECODE_INT_INTERNAL(number, maxnibbles, pnumber, evbuf, offset) \
do { \
ev_uint8_t *data; \
int len = EVBUFFER_LENGTH(evbuf) - offset; \
int len = evbuffer_get_length(evbuf) - offset; \
int nibbles = 0; \
\
if (len <= 0) \
@ -390,7 +390,7 @@ evtag_unmarshal_header(struct evbuffer *evbuf, ev_uint32_t *ptag)
if (evtag_decode_int(&len, evbuf) == -1)
return (-1);
if (EVBUFFER_LENGTH(evbuf) < len)
if (evbuffer_get_length(evbuf) < len)
return (-1);
return (len);
@ -442,7 +442,7 @@ evtag_unmarshal_int(struct evbuffer *evbuf, ev_uint32_t need_tag,
if (evtag_decode_int(&len, evbuf) == -1)
return (-1);
if (EVBUFFER_LENGTH(evbuf) < len)
if (evbuffer_get_length(evbuf) < len)
return (-1);
result = decode_int_internal(pinteger, evbuf, 0);
@ -468,7 +468,7 @@ evtag_unmarshal_int64(struct evbuffer *evbuf, ev_uint32_t need_tag,
if (evtag_decode_int(&len, evbuf) == -1)
return (-1);
if (EVBUFFER_LENGTH(evbuf) < len)
if (evbuffer_get_length(evbuf) < len)
return (-1);
result = decode_int64_internal(pinteger, evbuf, 0);

View File

@ -282,7 +282,7 @@ evrpc_request_cb(struct evhttp_request *req, void *arg)
/* let's verify the outside parameters */
if (req->type != EVHTTP_REQ_POST ||
EVBUFFER_LENGTH(req->input_buffer) <= 0)
evbuffer_get_length(req->input_buffer) <= 0)
goto error;
rpc_state = mm_calloc(1, sizeof(struct evrpc_req_generic));

32
http.c
View File

@ -412,7 +412,7 @@ evhttp_make_header_request(struct evhttp_connection *evcon,
evhttp_find_header(req->output_headers, "Content-Length") == NULL){
char size[12];
evutil_snprintf(size, sizeof(size), "%ld",
(long)EVBUFFER_LENGTH(req->output_buffer));
(long)evbuffer_get_length(req->output_buffer));
evhttp_add_header(req->output_headers, "Content-Length", size);
}
}
@ -508,7 +508,7 @@ evhttp_make_header_response(struct evhttp_connection *evcon,
*/
evhttp_maybe_add_content_length_header(
req->output_headers,
(long)EVBUFFER_LENGTH(req->output_buffer));
(long)evbuffer_get_length(req->output_buffer));
}
}
@ -552,7 +552,7 @@ evhttp_make_header(struct evhttp_connection *evcon, struct evhttp_request *req)
}
evbuffer_add(output, "\r\n", 2);
if (EVBUFFER_LENGTH(req->output_buffer) > 0) {
if (evbuffer_get_length(req->output_buffer) > 0) {
/*
* For a request, we add the POST data, for a reply, this
* is the regular data.
@ -741,7 +741,7 @@ evhttp_handle_chunked_read(struct evhttp_request *req, struct evbuffer *buf)
{
int len;
while ((len = EVBUFFER_LENGTH(buf)) > 0) {
while ((len = evbuffer_get_length(buf)) > 0) {
if (req->ntoread < 0) {
/* Read chunk size */
ev_int64_t ntoread;
@ -783,7 +783,7 @@ evhttp_handle_chunked_read(struct evhttp_request *req, struct evbuffer *buf)
req->flags |= EVHTTP_REQ_DEFER_FREE;
(*req->chunk_cb)(req, req->cb_arg);
evbuffer_drain(req->input_buffer,
EVBUFFER_LENGTH(req->input_buffer));
evbuffer_get_length(req->input_buffer));
req->flags &= ~EVHTTP_REQ_DEFER_FREE;
if ((req->flags & EVHTTP_REQ_NEEDS_FREE) != 0) {
return (REQUEST_CANCELED);
@ -843,19 +843,19 @@ evhttp_read_body(struct evhttp_connection *evcon, struct evhttp_request *req)
/* Read until connection close. */
evbuffer_add_buffer(req->input_buffer, buf);
} else if (req->chunk_cb != NULL ||
EVBUFFER_LENGTH(buf) >= req->ntoread) {
evbuffer_get_length(buf) >= req->ntoread) {
/* We've postponed moving the data until now, but we're
* about to use it. */
req->ntoread -= EVBUFFER_LENGTH(buf);
req->ntoread -= evbuffer_get_length(buf);
evbuffer_add_buffer(req->input_buffer, buf);
}
if (EVBUFFER_LENGTH(req->input_buffer) > 0 && req->chunk_cb != NULL) {
if (evbuffer_get_length(req->input_buffer) > 0 && req->chunk_cb != NULL) {
req->flags |= EVHTTP_REQ_DEFER_FREE;
(*req->chunk_cb)(req, req->cb_arg);
req->flags &= ~EVHTTP_REQ_DEFER_FREE;
evbuffer_drain(req->input_buffer,
EVBUFFER_LENGTH(req->input_buffer));
evbuffer_get_length(req->input_buffer));
if ((req->flags & EVHTTP_REQ_NEEDS_FREE) != 0) {
evhttp_request_free(req);
return;
@ -1032,9 +1032,9 @@ evhttp_connection_reset(struct evhttp_connection *evcon)
/* we need to clean up any buffered data */
tmp = bufferevent_get_output(evcon->bufev);
evbuffer_drain(tmp, EVBUFFER_LENGTH(tmp));
evbuffer_drain(tmp, evbuffer_get_length(tmp));
tmp = bufferevent_get_input(evcon->bufev);
evbuffer_drain(tmp, EVBUFFER_LENGTH(tmp));
evbuffer_drain(tmp, evbuffer_get_length(tmp));
evcon->state = EVCON_DISCONNECTED;
}
@ -1575,7 +1575,7 @@ evhttp_get_body_length(struct evhttp_request *req)
event_debug(("%s: bytes to read: %d (in buffer %ld)\n",
__func__, req->ntoread,
EVBUFFER_LENGTH(bufferevent_get_input(req->evcon->bufev))));
evbuffer_get_length(bufferevent_get_input(req->evcon->bufev))));
return (0);
}
@ -2029,13 +2029,13 @@ void
evhttp_send_reply_chunk(struct evhttp_request *req, struct evbuffer *databuf)
{
struct evbuffer *output = bufferevent_get_output(req->evcon->bufev);
if (EVBUFFER_LENGTH(databuf) == 0)
if (evbuffer_get_length(databuf) == 0)
return;
if (!evhttp_response_needs_body(req))
return;
if (req->chunked) {
evbuffer_add_printf(output, "%x\r\n",
(unsigned)EVBUFFER_LENGTH(databuf));
(unsigned)evbuffer_get_length(databuf));
}
evbuffer_add_buffer(output, databuf);
if (req->chunked) {
@ -2054,7 +2054,7 @@ evhttp_send_reply_end(struct evhttp_request *req)
evbuffer_add(output, "0\r\n\r\n", 5);
evhttp_write_buffer(req->evcon, evhttp_send_done, NULL);
req->chunked = 0;
} else if (EVBUFFER_LENGTH(output) == 0) {
} else if (evbuffer_get_length(output) == 0) {
/* let the connection know that we are done with the request */
evhttp_send_done(evcon, NULL);
} else {
@ -2132,7 +2132,7 @@ evhttp_encode_uri(const char *uri)
}
}
evbuffer_add(buf, "", 1);
p = mm_strdup((char *)EVBUFFER_DATA(buf));
p = mm_strdup((char*)evbuffer_pullup(buf, -1));
evbuffer_free(buf);
return (p);

View File

@ -559,11 +559,6 @@ int evbuffer_prepend(struct evbuffer *buf, const void *data, size_t size);
*/
int evbuffer_prepend_buffer(struct evbuffer *dst, struct evbuffer* src);
/** deprecated in favor of calling the functions directly */
#define EVBUFFER_LENGTH(x) evbuffer_get_length(x)
/** deprecated in favor of calling the functions directly */
#define EVBUFFER_DATA(x) evbuffer_pullup(x, -1)
/**
Prevent calls that modify an evbuffer from succeeding. A buffer may
frozen at the front, at the back, or at both the front and the back.

View File

@ -76,5 +76,10 @@ void evbuffer_setcb(struct evbuffer *buffer, evbuffer_cb cb, void *cbarg);
*/
unsigned char *evbuffer_find(struct evbuffer *buffer, const unsigned char *what, size_t len);
/** deprecated in favor of calling the functions directly */
#define EVBUFFER_LENGTH(x) evbuffer_get_length(x)
/** deprecated in favor of calling the functions directly */
#define EVBUFFER_DATA(x) evbuffer_pullup(x, -1)
#endif

View File

@ -60,6 +60,7 @@
#include "event2/event_compat.h"
#include "event2/tag.h"
#include "event2/buffer.h"
#include "event2/buffer_compat.h"
#include "event2/util.h"
#include "event-internal.h"
#include "log-internal.h"

View File

@ -115,7 +115,7 @@ test_evbuffer(void *ptr)
evbuffer_add_printf(evb, "%s/%d", "hello", 1);
evbuffer_validate(evb);
tt_assert(EVBUFFER_LENGTH(evb) == 7);
tt_assert(evbuffer_get_length(evb) == 7);
tt_assert(!memcmp((char*)EVBUFFER_DATA(evb), "hello/1", 1));
evbuffer_add_buffer(evb, evb_two);
@ -123,7 +123,7 @@ test_evbuffer(void *ptr)
evbuffer_drain(evb, strlen("hello/"));
evbuffer_validate(evb);
tt_assert(EVBUFFER_LENGTH(evb) == 1);
tt_assert(evbuffer_get_length(evb) == 1);
tt_assert(!memcmp((char*)EVBUFFER_DATA(evb), "1", 1));
evbuffer_add_printf(evb_two, "%s", "/hello");
@ -131,14 +131,14 @@ test_evbuffer(void *ptr)
evbuffer_add_buffer(evb, evb_two);
evbuffer_validate(evb);
tt_assert(EVBUFFER_LENGTH(evb_two) == 0);
tt_assert(EVBUFFER_LENGTH(evb) == 7);
tt_assert(evbuffer_get_length(evb_two) == 0);
tt_assert(evbuffer_get_length(evb) == 7);
tt_assert(!memcmp((char*)EVBUFFER_DATA(evb), "1/hello", 7) != 0);
memset(buffer, 0, sizeof(buffer));
evbuffer_add(evb, buffer, sizeof(buffer));
evbuffer_validate(evb);
tt_assert(EVBUFFER_LENGTH(evb) == 7 + 512);
tt_assert(evbuffer_get_length(evb) == 7 + 512);
tmp = (char *)evbuffer_pullup(evb, 7 + 512);
tt_assert(tmp);
@ -168,14 +168,14 @@ test_evbuffer(void *ptr)
evbuffer_validate(evb_two);
}
tt_assert(EVBUFFER_LENGTH(evb_two) == 0);
tt_assert(EVBUFFER_LENGTH(evb) == i * sizeof(buffer));
tt_assert(evbuffer_get_length(evb_two) == 0);
tt_assert(evbuffer_get_length(evb) == i * sizeof(buffer));
/* test remove buffer */
sz_tmp = sizeof(buffer)*2.5;
evbuffer_remove_buffer(evb, evb_two, sz_tmp);
tt_assert(EVBUFFER_LENGTH(evb_two) == sz_tmp);
tt_assert(EVBUFFER_LENGTH(evb) == sizeof(buffer) / 2);
tt_assert(evbuffer_get_length(evb_two) == sz_tmp);
tt_assert(evbuffer_get_length(evb) == sizeof(buffer) / 2);
evbuffer_validate(evb);
if (memcmp(evbuffer_pullup(
@ -327,7 +327,7 @@ test_evbuffer_readln(void *ptr)
cp = evbuffer_readln(evb, &sz, EVBUFFER_EOL_ANY);
if (!cp || sz != 5 || memcmp(cp, "more\0\0", 6))
tt_abort_msg("Not as expected");
tt_uint_op(EVBUFFER_LENGTH(evb), ==, 0);
tt_uint_op(evbuffer_get_length(evb), ==, 0);
evbuffer_validate(evb);
s = "\nno newline";
evbuffer_add(evb, s, strlen(s));
@ -340,8 +340,8 @@ test_evbuffer_readln(void *ptr)
cp = evbuffer_readln(evb, &sz, EVBUFFER_EOL_ANY);
tt_assert(!cp);
evbuffer_validate(evb);
evbuffer_drain(evb, EVBUFFER_LENGTH(evb));
tt_assert(EVBUFFER_LENGTH(evb) == 0);
evbuffer_drain(evb, evbuffer_get_length(evb));
tt_assert(evbuffer_get_length(evb) == 0);
evbuffer_validate(evb);
/* Test EOL_CRLF */
@ -398,7 +398,7 @@ test_evbuffer_readln(void *ptr)
cp = evbuffer_readln(evb, &sz, EVBUFFER_EOL_CRLF_STRICT);
tt_line_eq("More");
free(cp);
tt_assert(EVBUFFER_LENGTH(evb) == 0);
tt_assert(evbuffer_get_length(evb) == 0);
evbuffer_validate(evb);
/* Test LF */
@ -463,7 +463,7 @@ test_evbuffer_readln(void *ptr)
tt_line_eq("More");
free(cp); cp = NULL;
evbuffer_validate(evb);
tt_assert(EVBUFFER_LENGTH(evb) == 0);
tt_assert(evbuffer_get_length(evb) == 0);
test_ok = 1;
end:
@ -492,7 +492,7 @@ test_evbuffer_iterative(void *ptr)
}
}
tt_uint_op(sum, ==, EVBUFFER_LENGTH(buf));
tt_uint_op(sum, ==, evbuffer_get_length(buf));
end:
evbuffer_free(buf);
@ -665,7 +665,7 @@ test_evbuffer_callbacks(void *ptr)
evbuffer_cb_set_flags(buf, cb2, EVBUFFER_CB_ENABLED);
evbuffer_add_reference(buf, "Goodbye", 7, NULL, NULL); /*31->38*/
evbuffer_remove_cb_entry(buf, cb1);
evbuffer_drain(buf, EVBUFFER_LENGTH(buf)); /*38->0*/;
evbuffer_drain(buf, evbuffer_get_length(buf)); /*38->0*/;
tt_assert(-1 == evbuffer_remove_cb(buf, log_change_callback, NULL));
evbuffer_add(buf, "X", 1); /* 0->1 */
tt_assert(!evbuffer_remove_cb(buf, log_change_callback, buf_out2));
@ -674,22 +674,22 @@ test_evbuffer_callbacks(void *ptr)
"0->36; 36->26; 26->31; 31->38; ");
tt_str_op(evbuffer_pullup(buf_out2, -1), ==,
"0->36; 31->38; 38->0; 0->1; ");
evbuffer_drain(buf_out1, EVBUFFER_LENGTH(buf_out1));
evbuffer_drain(buf_out2, EVBUFFER_LENGTH(buf_out2));
evbuffer_drain(buf_out1, evbuffer_get_length(buf_out1));
evbuffer_drain(buf_out2, evbuffer_get_length(buf_out2));
/* Let's test the obsolete buffer_setcb function too. */
cb1 = evbuffer_add_cb(buf, log_change_callback, buf_out1);
cb2 = evbuffer_add_cb(buf, log_change_callback, buf_out2);
evbuffer_setcb(buf, self_draining_callback, NULL);
evbuffer_add_printf(buf, "This should get drained right away.");
tt_uint_op(EVBUFFER_LENGTH(buf), ==, 0);
tt_uint_op(EVBUFFER_LENGTH(buf_out1), ==, 0);
tt_uint_op(EVBUFFER_LENGTH(buf_out2), ==, 0);
tt_uint_op(evbuffer_get_length(buf), ==, 0);
tt_uint_op(evbuffer_get_length(buf_out1), ==, 0);
tt_uint_op(evbuffer_get_length(buf_out2), ==, 0);
evbuffer_setcb(buf, NULL, NULL);
evbuffer_add_printf(buf, "This will not.");
tt_str_op(evbuffer_pullup(buf, -1), ==, "This will not.");
evbuffer_drain(buf, EVBUFFER_LENGTH(buf));
evbuffer_drain(buf, evbuffer_get_length(buf));
#if 0
/* Now let's try a suspended callback. */
@ -703,7 +703,7 @@ test_evbuffer_callbacks(void *ptr)
evbuffer_cb_unsuspend(buf,cb2);
evbuffer_drain(buf, 4); /* 15->11 */
evbuffer_cb_unsuspend(buf,cb1);
evbuffer_drain(buf, EVBUFFER_LENGTH(buf)); /* 11->0 */
evbuffer_drain(buf, evbuffer_get_length(buf)); /* 11->0 */
tt_str_op(evbuffer_pullup(buf_out1, -1), ==,
"0->11; 11->11; 11->0; ");

View File

@ -77,7 +77,7 @@
static void
readcb(struct bufferevent *bev, void *arg)
{
if (EVBUFFER_LENGTH(bev->input) == 8333) {
if (evbuffer_get_length(bev->input) == 8333) {
struct evbuffer *evbuf = evbuffer_new();
assert(evbuf != NULL);
@ -86,7 +86,7 @@ readcb(struct bufferevent *bev, void *arg)
bufferevent_disable(bev, EV_READ);
if (EVBUFFER_LENGTH(evbuf) == 8333) {
if (evbuffer_get_length(evbuf) == 8333) {
test_ok++;
}
@ -97,7 +97,7 @@ readcb(struct bufferevent *bev, void *arg)
static void
writecb(struct bufferevent *bev, void *arg)
{
if (EVBUFFER_LENGTH(bev->output) == 0) {
if (evbuffer_get_length(bev->output) == 0) {
test_ok++;
}
}
@ -166,7 +166,7 @@ static void
wm_readcb(struct bufferevent *bev, void *arg)
{
struct evbuffer *evbuf = evbuffer_new();
int len = EVBUFFER_LENGTH(bev->input);
int len = evbuffer_get_length(bev->input);
static int nread;
assert(len >= 10 && len <= 20);
@ -188,9 +188,9 @@ wm_readcb(struct bufferevent *bev, void *arg)
static void
wm_writecb(struct bufferevent *bev, void *arg)
{
assert(EVBUFFER_LENGTH(bev->output) <= 100);
if (EVBUFFER_LENGTH(bev->output) == 0) {
evbuffer_drain(bev->output, EVBUFFER_LENGTH(bev->output));
assert(evbuffer_get_length(bev->output) <= 100);
if (evbuffer_get_length(bev->output) == 0) {
evbuffer_drain(bev->output, evbuffer_get_length(bev->output));
test_ok++;
}
}
@ -273,12 +273,12 @@ bufferevent_input_filter(struct evbuffer *src, struct evbuffer *dst,
const unsigned char *buffer;
int i;
buffer = evbuffer_pullup(src, EVBUFFER_LENGTH(src));
for (i = 0; i < EVBUFFER_LENGTH(src); i += 2) {
buffer = evbuffer_pullup(src, evbuffer_get_length(src));
for (i = 0; i < evbuffer_get_length(src); i += 2) {
assert(buffer[i] == 'x');
evbuffer_add(dst, buffer + i + 1, 1);
if (i + 2 > EVBUFFER_LENGTH(src))
if (i + 2 > evbuffer_get_length(src))
break;
}
@ -295,13 +295,13 @@ bufferevent_output_filter(struct evbuffer *src, struct evbuffer *dst,
const unsigned char *buffer;
int i;
buffer = evbuffer_pullup(src, EVBUFFER_LENGTH(src));
for (i = 0; i < EVBUFFER_LENGTH(src); ++i) {
buffer = evbuffer_pullup(src, evbuffer_get_length(src));
for (i = 0; i < evbuffer_get_length(src); ++i) {
evbuffer_add(dst, "x", 1);
evbuffer_add(dst, buffer + i, 1);
}
evbuffer_drain(src, EVBUFFER_LENGTH(src));
evbuffer_drain(src, evbuffer_get_length(src));
return (BEV_OK);
}

View File

@ -139,7 +139,7 @@ zlib_input_filter(struct evbuffer *src, struct evbuffer *dst,
assert(res == Z_OK || res == Z_STREAM_END);
}
} while (EVBUFFER_LENGTH(src) > 0);
} while (evbuffer_get_length(src) > 0);
++infilter_calls;
@ -184,7 +184,7 @@ zlib_output_filter(struct evbuffer *src, struct evbuffer *dst,
assert(res == Z_OK || res == Z_STREAM_END);
}
} while (EVBUFFER_LENGTH(src) > 0);
} while (evbuffer_get_length(src) > 0);
++outfilter_calls;
@ -198,7 +198,7 @@ zlib_output_filter(struct evbuffer *src, struct evbuffer *dst,
static void
readcb(struct bufferevent *bev, void *arg)
{
if (EVBUFFER_LENGTH(bufferevent_get_input(bev)) == 8333) {
if (evbuffer_get_length(bufferevent_get_input(bev)) == 8333) {
struct evbuffer *evbuf = evbuffer_new();
assert(evbuf != NULL);
@ -207,7 +207,7 @@ readcb(struct bufferevent *bev, void *arg)
bufferevent_disable(bev, EV_READ);
if (EVBUFFER_LENGTH(evbuf) == 8333) {
if (evbuffer_get_length(evbuf) == 8333) {
++readcb_finished;
}
@ -218,7 +218,7 @@ readcb(struct bufferevent *bev, void *arg)
static void
writecb(struct bufferevent *bev, void *arg)
{
if (EVBUFFER_LENGTH(bufferevent_get_output(bev)) == 0) {
if (evbuffer_get_length(bufferevent_get_output(bev)) == 0) {
++writecb_finished;
}
}