diff options
author | Brad Smith <brad@cvs.openbsd.org> | 2006-03-18 20:23:43 +0000 |
---|---|---|
committer | Brad Smith <brad@cvs.openbsd.org> | 2006-03-18 20:23:43 +0000 |
commit | 67092fb0b4f670759fe368d504a5393fde2d6c57 (patch) | |
tree | e43ae77f2dbc4fcefcc5fd51b7cb82c9dc002828 /lib/libevent/evbuffer.c | |
parent | aa453a0c31a4662f565dc06b82d641c008a5513e (diff) |
- limit the amount of data bufferevents are going to consume to something
reasonable; in some circumstances it could happen that libevent happily
allocated 100MB in read buffers without telling the user; found by
christopher maxwell - parts of these changes are from his patch.
- allow setting an event base for bufferevents; from phil oleson
- improved manpage from Phil Oleson
From libevent CVS
Diffstat (limited to 'lib/libevent/evbuffer.c')
-rw-r--r-- | lib/libevent/evbuffer.c | 32 |
1 files changed, 29 insertions, 3 deletions
diff --git a/lib/libevent/evbuffer.c b/lib/libevent/evbuffer.c index fd16a132877..9a0a2a96381 100644 --- a/lib/libevent/evbuffer.c +++ b/lib/libevent/evbuffer.c @@ -1,4 +1,4 @@ -/* $OpenBSD: evbuffer.c,v 1.7 2006/02/09 06:18:18 brad Exp $ */ +/* $OpenBSD: evbuffer.c,v 1.8 2006/03/18 20:23:42 brad Exp $ */ /* * Copyright (c) 2002-2004 Niels Provos <provos@citi.umich.edu> @@ -94,13 +94,21 @@ bufferevent_readcb(int fd, short event, void *arg) int res = 0; short what = EVBUFFER_READ; size_t len; + int howmuch = -1; if (event == EV_TIMEOUT) { what |= EVBUFFER_TIMEOUT; goto error; } - res = evbuffer_read(bufev->input, fd, -1); + /* + * If we have a high watermark configured then we don't want to + * read more data than would make us reach the watermark. + */ + if (bufev->wm_read.high != 0) + howmuch = bufev->wm_read.high; + + res = evbuffer_read(bufev->input, fd, howmuch); if (res == -1) { if (errno == EAGAIN || errno == EINTR) goto reschedule; @@ -228,7 +236,12 @@ bufferevent_new(int fd, evbuffercb readcb, evbuffercb writecb, bufev->cbarg = cbarg; - bufev->enabled = EV_READ | EV_WRITE; + /* + * Set to EV_WRITE so that using bufferevent_write is going to + * trigger a callback. Reading needs to be explicitly enabled + * because otherwise no data will be available. + */ + bufev->enabled = EV_WRITE; return (bufev); } @@ -374,3 +387,16 @@ bufferevent_setwatermark(struct bufferevent *bufev, short events, bufferevent_read_pressure_cb(bufev->input, 0, EVBUFFER_LENGTH(bufev->input), bufev); } + +int +bufferevent_base_set(struct event_base *base, struct bufferevent *bufev) +{ + int res; + + res = event_base_set(base, &bufev->ev_read); + if (res == -1) + return (res); + + res = event_base_set(base, &bufev->ev_write); + return (res); +} |