Do not use the "evbuffer_" prefix to denote parts of bufferevents.

This is a bit of an interface doozy, but it's really needed in order
to be able to document this stuff without apologizing it.  This patch
does the following renamings:

   evbuffercb -> bufferevent_data_cb
   everrorcb -> bufferevent_event_cb
   EVBUFFER_(READ,WRITE,...) -> BEV_EVENT_(...)
   EVBUFFER_(INPUT,OUTPUT) -> bufferevent_get_(input,output)

All the old names are available in event2/bufferevent_compat.h

svn:r1283
This commit is contained in:
Nick Mathewson 2009-05-13 20:36:56 +00:00
parent f11dff2c7a
commit 83f46e51d7
11 changed files with 82 additions and 69 deletions

View File

@ -19,7 +19,9 @@ Changes in 2.0.2-alpha:
o New function to automate connecting on a socket-based bufferevent.
o New functions to automate listening for incoming TCP connections.
o Do case-insensitive checks with a locale-independent comparison function.
o Rename the evbuffercb and everrorcb callbacks to bufferevent_data_cb and bufferevent_event_cb respectively. The old names are available in bufferevent_compat.h.
o Rename the EVBUFFER_* codes used by bufferevent event callbacks to BEV_EVENT_*, to avoid namespace collision with evbuffer flags. The old names are available in bufferevent_compat.h.
o Move the EVBUFFER_INPUT and EVBUFFER_OUTPUT macros to bufferevent_compat.h
Changes in 2.0.1-alpha:
o free minheap on event_base_free(); from Christopher Layne

View File

@ -252,7 +252,8 @@ bufferevent_init_common(struct bufferevent_private *bufev_private,
void
bufferevent_setcb(struct bufferevent *bufev,
evbuffercb readcb, evbuffercb writecb, everrorcb errorcb, void *cbarg)
bufferevent_data_cb readcb, bufferevent_data_cb writecb,
bufferevent_event_cb errorcb, void *cbarg)
{
BEV_LOCK(bufev);

View File

@ -260,7 +260,7 @@ be_pair_flush(struct bufferevent *bev, short iotype,
if (mode == BEV_FINISHED) {
if (partner->errorcb)
(*partner->errorcb)(partner,
iotype|EVBUFFER_EOF, partner->cbarg);
iotype|BEV_EVENT_EOF, partner->cbarg);
}
return 0;
}

View File

@ -115,11 +115,11 @@ bufferevent_readcb(evutil_socket_t fd, short event, void *arg)
struct bufferevent *bufev = arg;
struct evbuffer *input;
int res = 0;
short what = EVBUFFER_READ;
short what = BEV_EVENT_READING;
int howmuch = -1;
if (event == EV_TIMEOUT) {
what |= EVBUFFER_TIMEOUT;
what |= BEV_EVENT_TIMEOUT;
goto error;
}
@ -147,10 +147,10 @@ bufferevent_readcb(evutil_socket_t fd, short event, void *arg)
if (EVUTIL_ERR_RW_RETRIABLE(err))
goto reschedule;
/* error case */
what |= EVBUFFER_ERROR;
what |= BEV_EVENT_ERROR;
} else if (res == 0) {
/* eof case */
what |= EVBUFFER_EOF;
what |= BEV_EVENT_EOF;
}
if (res <= 0)
@ -179,15 +179,15 @@ bufferevent_writecb(evutil_socket_t fd, short event, void *arg)
struct bufferevent_private *bufev_p =
EVUTIL_UPCAST(bufev, struct bufferevent_private, bev);
int res = 0;
short what = EVBUFFER_WRITE;
short what = BEV_EVENT_WRITING;
if (event == EV_TIMEOUT) {
what |= EVBUFFER_TIMEOUT;
what |= BEV_EVENT_TIMEOUT;
goto error;
}
if (bufev_p->connecting) {
bufev_p->connecting = 0;
_bufferevent_run_errorcb(bufev, EVBUFFER_CONNECTED);
_bufferevent_run_errorcb(bufev, BEV_EVENT_CONNECTED);
if (!(bufev->enabled & EV_WRITE)) {
event_del(&bufev->ev_write);
return;
@ -202,10 +202,10 @@ bufferevent_writecb(evutil_socket_t fd, short event, void *arg)
int err = evutil_socket_geterror(fd);
if (EVUTIL_ERR_RW_RETRIABLE(err))
goto reschedule;
what |= EVBUFFER_ERROR;
what |= BEV_EVENT_ERROR;
} else if (res == 0) {
/* eof case */
what |= EVBUFFER_EOF;
what |= BEV_EVENT_EOF;
}
if (res <= 0)
goto error;
@ -298,11 +298,11 @@ bufferevent_socket_connect(struct bufferevent *bev,
return 0;
}
}
_bufferevent_run_errorcb(bev, EVBUFFER_ERROR);
_bufferevent_run_errorcb(bev, BEV_EVENT_ERROR);
/* do something about the error? */
} else {
/* The connect succeeded already. How odd. */
_bufferevent_run_errorcb(bev, EVBUFFER_CONNECTED);
_bufferevent_run_errorcb(bev, BEV_EVENT_CONNECTED);
}
return 0;
@ -320,8 +320,9 @@ bufferevent_socket_connect(struct bufferevent *bev,
*/
struct bufferevent *
bufferevent_new(evutil_socket_t fd, evbuffercb readcb, evbuffercb writecb,
everrorcb errorcb, void *cbarg)
bufferevent_new(evutil_socket_t fd,
bufferevent_data_cb readcb, bufferevent_data_cb writecb,
bufferevent_event_cb errorcb, void *cbarg)
{
struct bufferevent *bufev;

8
http.c
View File

@ -1092,7 +1092,7 @@ evhttp_error_cb(struct bufferevent *bufev, short what, void *arg)
switch (evcon->state) {
case EVCON_CONNECTING:
if (what == EVBUFFER_TIMEOUT) {
if (what == BEV_EVENT_TIMEOUT) {
event_debug(("%s: connection timeout for \"%s:%d\" on %d",
__func__, evcon->address, evcon->port,
evcon->fd));
@ -1103,7 +1103,7 @@ evhttp_error_cb(struct bufferevent *bufev, short what, void *arg)
case EVCON_READING_BODY:
if (!req->chunked && req->ntoread < 0
&& what == (EVBUFFER_READ|EVBUFFER_EOF)) {
&& what == (BEV_EVENT_READING|BEV_EVENT_EOF)) {
/* EOF on read can be benign */
evhttp_connection_done(evcon);
return;
@ -1135,9 +1135,9 @@ evhttp_error_cb(struct bufferevent *bufev, short what, void *arg)
return;
}
if (what & EVBUFFER_TIMEOUT) {
if (what & BEV_EVENT_TIMEOUT) {
evhttp_connection_fail(evcon, EVCON_HTTP_TIMEOUT);
} else if (what & (EVBUFFER_EOF|EVBUFFER_ERROR)) {
} else if (what & (BEV_EVENT_EOF|BEV_EVENT_ERROR)) {
evhttp_connection_fail(evcon, EVCON_HTTP_EOF);
} else {
evhttp_connection_fail(evcon, EVCON_HTTP_BUFFER_ERROR);

View File

@ -73,12 +73,12 @@ extern "C" {
/* Just for error reporting - use other constants otherwise */
#define EVBUFFER_READ 0x01 /**< error encountered while reading */
#define EVBUFFER_WRITE 0x02 /**< error encountered while writing */
#define EVBUFFER_EOF 0x10 /**< eof file reached */
#define EVBUFFER_ERROR 0x20 /**< unrecoverable error encountered */
#define EVBUFFER_TIMEOUT 0x40 /**< user specified timeout reached */
#define EVBUFFER_CONNECTED 0x80 /**< connect operation finished. */
#define BEV_EVENT_READING 0x01 /**< error encountered while reading */
#define BEV_EVENT_WRITING 0x02 /**< error encountered while writing */
#define BEV_EVENT_EOF 0x10 /**< eof file reached */
#define BEV_EVENT_ERROR 0x20 /**< unrecoverable error encountered */
#define BEV_EVENT_TIMEOUT 0x40 /**< user specified timeout reached */
#define BEV_EVENT_CONNECTED 0x80 /**< connect operation finished. */
struct bufferevent;
struct event_base;
struct evbuffer;
@ -97,9 +97,7 @@ struct sockaddr;
@param bev the bufferevent that triggered the callback
@param ctx the user specified context for this bufferevent
*/
/* XXXX we should rename this to bufferevent_cb; evbuffercb implies that it's
* a cb on an evbuffer. We should retain the old name in bufferevent_compat. */
typedef void (*evbuffercb)(struct bufferevent *bev, void *ctx);
typedef void (*bufferevent_data_cb)(struct bufferevent *bev, void *ctx);
/**
type defintion for the error callback of a bufferevent.
@ -108,14 +106,14 @@ typedef void (*evbuffercb)(struct bufferevent *bev, void *ctx);
unrecoverable error was encountered.
@param bev the bufferevent for which the error condition was reached
@param what a conjunction of flags: EVBUFFER_READ or EVBUFFER write to
indicate if the error was encountered on the read or write path,
and one of the following flags: EVBUFFER_EOF, EVBUFFER_ERROR or
EVBUFFER_TIMEOUT.
@param what a conjunction of flags: BEV_EVENT_READING or BEV_EVENT_WRITING
to indicate if the error was encountered on the read or write path,
and one of the following flags: BEV_EVENT_EOF, BEV_EVENT_ERROR,
BEV_EVENT_TIMEOUT, BEV_EVENT_CONNECTED.
@param ctx the user specified context for this bufferevent
*/
/* XXXX we should rename this to bufferevent_error_cb; see above. */
typedef void (*everrorcb)(struct bufferevent *bev, short what, void *ctx);
typedef void (*bufferevent_event_cb)(struct bufferevent *bev, short what, void *ctx);
/** Options that can be specified when creating a bufferevent */
enum bufferevent_options {
@ -147,7 +145,7 @@ struct bufferevent *bufferevent_socket_new(struct event_base *base, evutil_socke
/**
Launch a connect() attempt with a socket. When the connect succeeds,
the errorcb will be invoked with EVBUFFER_CONNECTED set.
the errorcb will be invoked with BEV_EVENT_CONNECTED set.
If the bufferevent does not already have a socket set, we allocate a new
socket here and make it nonblocking before we begin.
@ -204,7 +202,8 @@ void bufferevent_free(struct bufferevent *bufev);
@see bufferevent_new()
*/
void bufferevent_setcb(struct bufferevent *bufev,
evbuffercb readcb, evbuffercb writecb, everrorcb errorcb, void *cbarg);
bufferevent_data_cb readcb, bufferevent_data_cb writecb,
bufferevent_event_cb errorcb, void *cbarg);
/**
Changes the file descriptor on which the bufferevent operates.
@ -342,11 +341,6 @@ void bufferevent_set_timeouts(struct bufferevent *bufev,
void bufferevent_setwatermark(struct bufferevent *bufev, short events,
size_t lowmark, size_t highmark);
/** macro for getting access to the input buffer of a bufferevent */
#define EVBUFFER_INPUT(x) bufferevent_get_input(x)
/** macro for getting access to the output buffer of a bufferevent */
#define EVBUFFER_OUTPUT(x) bufferevent_get_output(x)
/**
Flags that can be passed into filters to let them know how to
deal with the incoming data.

View File

@ -28,6 +28,9 @@
#ifndef _EVENT2_BUFFEREVENT_COMPAT_H_
#define _EVENT2_BUFFEREVENT_COMPAT_H_
#define evbuffercb bufferevent_data_cb
#define everrorcb bufferevent_event_cb
/**
Create a new bufferevent for an fd.
@ -79,4 +82,16 @@ struct bufferevent *bufferevent_new(evutil_socket_t fd,
void bufferevent_settimeout(struct bufferevent *bufev,
int timeout_read, int timeout_write);
#define EVBUFFER_READ BEV_EVENT_READING
#define EVBUFFER_WRITE BEV_EVENT_WRITING
#define EVBUFFER_EOF BEV_EVENT_EOF
#define EVBUFFER_ERROR BEV_EVENT_ERROR
#define EVBUFFER_TIMEOUT BEV_EVENT_TIMEOUT
#define EVBUFFER_CONNECTED BEV_EVENT_CONNECTED
/** macro for getting access to the input buffer of a bufferevent */
#define EVBUFFER_INPUT(x) bufferevent_get_input(x)
/** macro for getting access to the output buffer of a bufferevent */
#define EVBUFFER_OUTPUT(x) bufferevent_get_output(x)
#endif

View File

@ -97,9 +97,9 @@ struct bufferevent {
struct event_watermark wm_read;
struct event_watermark wm_write;
evbuffercb readcb;
evbuffercb writecb;
everrorcb errorcb;
bufferevent_data_cb readcb;
bufferevent_data_cb writecb;
bufferevent_event_cb errorcb;
void *cbarg;
struct timeval timeout_read;

View File

@ -81,7 +81,7 @@ errorcb(struct bufferevent *b, short what, void *arg)
{
struct request_info *ri = arg;
struct timeval now, diff;
if (what & EVBUFFER_EOF) {
if (what & BEV_EVENT_EOF) {
++total_n_handled;
total_n_bytes += ri->n_read;
gettimeofday(&now, NULL);

View File

@ -405,15 +405,15 @@ static void
reader_eventcb(struct bufferevent *bev, short what, void *ctx)
{
struct event_base *base = ctx;
if (what & EVBUFFER_ERROR) {
if (what & BEV_EVENT_ERROR) {
perror("foobar");
TT_FAIL(("got connector error %d", (int)what));
return;
}
if (what & EVBUFFER_CONNECTED) {
if (what & BEV_EVENT_CONNECTED) {
bufferevent_enable(bev, EV_READ);
}
if (what & EVBUFFER_EOF) {
if (what & BEV_EVENT_EOF) {
char buf[512];
size_t n;
n = bufferevent_read(bev, buf, sizeof(buf)-1);

View File

@ -178,19 +178,19 @@ http_readcb(struct bufferevent *bev, void *arg)
{
const char *what = BASIC_REQUEST_BODY;
event_debug(("%s: %s\n", __func__, EVBUFFER_DATA(EVBUFFER_INPUT(bev))));
event_debug(("%s: %s\n", __func__, EVBUFFER_DATA(bufferevent_get_input(bev))));
if (evbuffer_find(EVBUFFER_INPUT(bev),
if (evbuffer_find(bufferevent_get_input(bev),
(const unsigned char*) what, strlen(what)) != NULL) {
struct evhttp_request *req = evhttp_request_new(NULL, NULL);
enum message_read_status done;
req->kind = EVHTTP_RESPONSE;
done = evhttp_parse_firstline(req, EVBUFFER_INPUT(bev));
done = evhttp_parse_firstline(req, bufferevent_get_input(bev));
if (done != ALL_DATA_READ)
goto out;
done = evhttp_parse_headers(req, EVBUFFER_INPUT(bev));
done = evhttp_parse_headers(req, bufferevent_get_input(bev));
if (done != ALL_DATA_READ)
goto out;
@ -212,7 +212,7 @@ http_readcb(struct bufferevent *bev, void *arg)
static void
http_writecb(struct bufferevent *bev, void *arg)
{
if (EVBUFFER_LENGTH(EVBUFFER_OUTPUT(bev)) == 0) {
if (EVBUFFER_LENGTH(bufferevent_get_output(bev)) == 0) {
/* enable reading of the reply */
bufferevent_enable(bev, EV_READ);
test_ok++;
@ -1171,7 +1171,7 @@ static void
http_failure_readcb(struct bufferevent *bev, void *arg)
{
const char *what = "400 Bad Request";
if (evbuffer_find(EVBUFFER_INPUT(bev),
if (evbuffer_find(bufferevent_get_input(bev),
(const unsigned char*) what, strlen(what)) != NULL) {
test_ok = 2;
bufferevent_disable(bev, EV_READ);
@ -1480,7 +1480,7 @@ http_incomplete_writecb(struct bufferevent *bev, void *arg)
/* terminate the write side to simulate EOF */
shutdown(fd, SHUT_WR);
}
if (EVBUFFER_LENGTH(EVBUFFER_OUTPUT(bev)) == 0) {
if (EVBUFFER_LENGTH(bufferevent_get_output(bev)) == 0) {
/* enable reading of the reply */
bufferevent_enable(bev, EV_READ);
test_ok++;
@ -1574,11 +1574,11 @@ http_chunked_errorcb(struct bufferevent *bev, short what, void *arg)
enum message_read_status done;
req->kind = EVHTTP_RESPONSE;
done = evhttp_parse_firstline(req, EVBUFFER_INPUT(bev));
done = evhttp_parse_firstline(req, bufferevent_get_input(bev));
if (done != ALL_DATA_READ)
goto out;
done = evhttp_parse_headers(req, EVBUFFER_INPUT(bev));
done = evhttp_parse_headers(req, bufferevent_get_input(bev));
if (done != ALL_DATA_READ)
goto out;
@ -1590,7 +1590,7 @@ http_chunked_errorcb(struct bufferevent *bev, short what, void *arg)
if (header == NULL || strcmp(header, "close"))
goto out;
header = evbuffer_readln(EVBUFFER_INPUT(bev), NULL, EVBUFFER_EOL_CRLF);
header = evbuffer_readln(bufferevent_get_input(bev), NULL, EVBUFFER_EOL_CRLF);
if (header == NULL)
goto out;
/* 13 chars */
@ -1598,13 +1598,13 @@ http_chunked_errorcb(struct bufferevent *bev, short what, void *arg)
goto out;
free((char*)header);
if (strncmp((char *)evbuffer_pullup(EVBUFFER_INPUT(bev), 13),
if (strncmp((char *)evbuffer_pullup(bufferevent_get_input(bev), 13),
"This is funny", 13))
goto out;
evbuffer_drain(EVBUFFER_INPUT(bev), 13 + 2);
evbuffer_drain(bufferevent_get_input(bev), 13 + 2);
header = evbuffer_readln(EVBUFFER_INPUT(bev), NULL, EVBUFFER_EOL_CRLF);
header = evbuffer_readln(bufferevent_get_input(bev), NULL, EVBUFFER_EOL_CRLF);
if (header == NULL)
goto out;
/* 18 chars */
@ -1612,13 +1612,13 @@ http_chunked_errorcb(struct bufferevent *bev, short what, void *arg)
goto out;
free((char *)header);
if (strncmp((char *)evbuffer_pullup(EVBUFFER_INPUT(bev), 18),
if (strncmp((char *)evbuffer_pullup(bufferevent_get_input(bev), 18),
"but not hilarious.", 18))
goto out;
evbuffer_drain(EVBUFFER_INPUT(bev), 18 + 2);
evbuffer_drain(bufferevent_get_input(bev), 18 + 2);
header = evbuffer_readln(EVBUFFER_INPUT(bev), NULL, EVBUFFER_EOL_CRLF);
header = evbuffer_readln(bufferevent_get_input(bev), NULL, EVBUFFER_EOL_CRLF);
if (header == NULL)
goto out;
/* 8 chars */
@ -1626,13 +1626,13 @@ http_chunked_errorcb(struct bufferevent *bev, short what, void *arg)
goto out;
free((char *)header);
if (strncmp((char *)evbuffer_pullup(EVBUFFER_INPUT(bev), 8),
if (strncmp((char *)evbuffer_pullup(bufferevent_get_input(bev), 8),
"bwv 1052.", 8))
goto out;
evbuffer_drain(EVBUFFER_INPUT(bev), 8 + 2);
evbuffer_drain(bufferevent_get_input(bev), 8 + 2);
header = evbuffer_readln(EVBUFFER_INPUT(bev), NULL, EVBUFFER_EOL_CRLF);
header = evbuffer_readln(bufferevent_get_input(bev), NULL, EVBUFFER_EOL_CRLF);
if (header == NULL)
goto out;
/* 0 chars */
@ -1652,7 +1652,7 @@ out:
static void
http_chunked_writecb(struct bufferevent *bev, void *arg)
{
if (EVBUFFER_LENGTH(EVBUFFER_OUTPUT(bev)) == 0) {
if (EVBUFFER_LENGTH(bufferevent_get_output(bev)) == 0) {
/* enable reading of the reply */
bufferevent_enable(bev, EV_READ);
test_ok++;