diff options
author | Nicholas Marriott <nicm@cvs.openbsd.org> | 2010-04-21 20:02:41 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@cvs.openbsd.org> | 2010-04-21 20:02:41 +0000 |
commit | 483c556c961377c65bc37a43cba770bfb7f24db2 (patch) | |
tree | f12eebcedd009fa08292bf672d9230e65b401f59 /lib/libevent/evbuffer.c | |
parent | 478d2f807269d4a1dc2066ed302f9716adb8b3f9 (diff) |
Update libevent to 1.4.13.
This is the core library only, the DNS parts are removed and it does not
include the other extra bits (HTTP, DNS, and RPC), a separate port for
these will appear in due course.
Thanks to jsg, sthen, alek, gilles, jacekm, bernd and any others I've
forgotten for testing/comments.
Note that /usr/include/evdns.h should be removed after updating.
ok deraadt
Diffstat (limited to 'lib/libevent/evbuffer.c')
-rw-r--r-- | lib/libevent/evbuffer.c | 72 |
1 files changed, 57 insertions, 15 deletions
diff --git a/lib/libevent/evbuffer.c b/lib/libevent/evbuffer.c index 25655cf548d..1c0f46e0a2c 100644 --- a/lib/libevent/evbuffer.c +++ b/lib/libevent/evbuffer.c @@ -1,4 +1,4 @@ -/* $OpenBSD: evbuffer.c,v 1.11 2008/05/02 18:26:42 brad Exp $ */ +/* $OpenBSD: evbuffer.c,v 1.12 2010/04/21 20:02:40 nicm Exp $ */ /* * Copyright (c) 2002-2004 Niels Provos <provos@citi.umich.edu> @@ -45,11 +45,15 @@ #include <stdarg.h> #endif +#ifdef WIN32 +#include <winsock2.h> +#endif + +#include "evutil.h" #include "event.h" /* prototypes */ -void bufferevent_setwatermark(struct bufferevent *, short, size_t, size_t); void bufferevent_read_pressure_cb(struct evbuffer *, size_t, size_t, void *); static int @@ -58,7 +62,7 @@ bufferevent_add(struct event *ev, int timeout) struct timeval tv, *ptv = NULL; if (timeout) { - timerclear(&tv); + evutil_timerclear(&tv); tv.tv_sec = timeout; ptv = &tv; } @@ -66,7 +70,7 @@ bufferevent_add(struct event *ev, int timeout) return (event_add(ev, ptv)); } -/* +/* * This callback is executed when the size of the input buffer changes. * We use it to apply back pressure on the reading side. */ @@ -75,7 +79,7 @@ void bufferevent_read_pressure_cb(struct evbuffer *buf, size_t old, size_t now, void *arg) { struct bufferevent *bufev = arg; - /* + /* * If we are below the watermark then reschedule reading if it's * still enabled. */ @@ -105,8 +109,17 @@ bufferevent_readcb(int fd, short event, void *arg) * 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; + if (bufev->wm_read.high != 0) { + howmuch = bufev->wm_read.high - EVBUFFER_LENGTH(bufev->input); + /* we might have lowered the watermark, stop reading */ + if (howmuch <= 0) { + struct evbuffer *buf = bufev->input; + event_del(&bufev->ev_read); + evbuffer_setcb(buf, + bufferevent_read_pressure_cb, bufev); + return; + } + } res = evbuffer_read(bufev->input, fd, howmuch); if (res == -1) { @@ -128,13 +141,12 @@ bufferevent_readcb(int fd, short event, void *arg) len = EVBUFFER_LENGTH(bufev->input); if (bufev->wm_read.low != 0 && len < bufev->wm_read.low) return; - if (bufev->wm_read.high != 0 && len > bufev->wm_read.high) { + if (bufev->wm_read.high != 0 && len >= bufev->wm_read.high) { struct evbuffer *buf = bufev->input; event_del(&bufev->ev_read); - /* Now schedule a callback for us */ + /* Now schedule a callback for us when the buffer changes */ evbuffer_setcb(buf, bufferevent_read_pressure_cb, bufev); - return; } /* Invoke the user callback - must always be called last */ @@ -243,11 +255,7 @@ bufferevent_new(int fd, evbuffercb readcb, evbuffercb writecb, event_set(&bufev->ev_read, fd, EV_READ, bufferevent_readcb, bufev); event_set(&bufev->ev_write, fd, EV_WRITE, bufferevent_writecb, bufev); - bufev->readcb = readcb; - bufev->writecb = writecb; - bufev->errorcb = errorcb; - - bufev->cbarg = cbarg; + bufferevent_setcb(bufev, readcb, writecb, errorcb, cbarg); /* * Set to EV_WRITE so that using bufferevent_write is going to @@ -259,6 +267,33 @@ bufferevent_new(int fd, evbuffercb readcb, evbuffercb writecb, return (bufev); } +void +bufferevent_setcb(struct bufferevent *bufev, + evbuffercb readcb, evbuffercb writecb, everrorcb errorcb, void *cbarg) +{ + bufev->readcb = readcb; + bufev->writecb = writecb; + bufev->errorcb = errorcb; + + bufev->cbarg = cbarg; +} + +void +bufferevent_setfd(struct bufferevent *bufev, int fd) +{ + event_del(&bufev->ev_read); + event_del(&bufev->ev_write); + + event_set(&bufev->ev_read, fd, EV_READ, bufferevent_readcb, bufev); + event_set(&bufev->ev_write, fd, EV_WRITE, bufferevent_writecb, bufev); + if (bufev->ev_base != NULL) { + event_base_set(bufev->ev_base, &bufev->ev_read); + event_base_set(bufev->ev_base, &bufev->ev_write); + } + + /* might have to manually trigger event registration */ +} + int bufferevent_priority_set(struct bufferevent *bufev, int priority) { @@ -376,6 +411,11 @@ bufferevent_settimeout(struct bufferevent *bufev, int timeout_read, int timeout_write) { bufev->timeout_read = timeout_read; bufev->timeout_write = timeout_write; + + if (event_pending(&bufev->ev_read, EV_READ, NULL)) + bufferevent_add(&bufev->ev_read, timeout_read); + if (event_pending(&bufev->ev_write, EV_WRITE, NULL)) + bufferevent_add(&bufev->ev_write, timeout_write); } /* @@ -406,6 +446,8 @@ bufferevent_base_set(struct event_base *base, struct bufferevent *bufev) { int res; + bufev->ev_base = base; + res = event_base_set(base, &bufev->ev_read); if (res == -1) return (res); |