aboutsummaryrefslogtreecommitdiff
path: root/libevent
diff options
context:
space:
mode:
Diffstat (limited to 'libevent')
-rw-r--r--libevent/buffer.c16
-rw-r--r--libevent/evbuffer.c8
-rw-r--r--libevent/event-internal.h2
-rw-r--r--libevent/event.c21
-rw-r--r--libevent/event.h17
-rw-r--r--libevent/evsignal.h2
-rw-r--r--libevent/kqueue.c28
-rw-r--r--libevent/log.c14
-rw-r--r--libevent/log.h2
-rw-r--r--libevent/poll.c7
-rw-r--r--libevent/select.c4
-rw-r--r--libevent/signal.c4
12 files changed, 68 insertions, 57 deletions
diff --git a/libevent/buffer.c b/libevent/buffer.c
index 0327eb549383..e01a5749d807 100644
--- a/libevent/buffer.c
+++ b/libevent/buffer.c
@@ -1,3 +1,5 @@
+/* $OpenBSD: buffer.c,v 1.14 2007/03/19 15:12:49 millert Exp $ */
+
/*
* Copyright (c) 2002, 2003 Niels Provos <provos@citi.umich.edu>
* All rights reserved.
@@ -62,7 +64,7 @@ struct evbuffer *
evbuffer_new(void)
{
struct evbuffer *buffer;
-
+
buffer = calloc(1, sizeof(struct evbuffer));
return (buffer);
@@ -76,7 +78,7 @@ evbuffer_free(struct evbuffer *buffer)
free(buffer);
}
-/*
+/*
* This is a destructive add. The data from one buffer moves into
* the other buffer.
*/
@@ -104,16 +106,16 @@ evbuffer_add_buffer(struct evbuffer *outbuf, struct evbuffer *inbuf)
SWAP(outbuf, inbuf);
SWAP(inbuf, &tmp);
- /*
+ /*
* Optimization comes with a price; we need to notify the
* buffer if necessary of the changes. oldoff is the amount
- * of data that we transfered from inbuf to outbuf
+ * of data that we transferred from inbuf to outbuf
*/
if (inbuf->off != oldoff && inbuf->cb != NULL)
(*inbuf->cb)(inbuf, oldoff, inbuf->off, inbuf->cbarg);
if (oldoff && outbuf->cb != NULL)
(*outbuf->cb)(outbuf, 0, oldoff, outbuf->cbarg);
-
+
return (0);
}
@@ -196,7 +198,7 @@ evbuffer_remove(struct evbuffer *buf, void *data, size_t datlen)
memcpy(data, buf->buffer, nread);
evbuffer_drain(buf, nread);
-
+
return (nread);
}
@@ -371,7 +373,7 @@ evbuffer_read(struct evbuffer *buf, int fd, int howmuch)
if (n < EVBUFFER_MAX_READ)
n = EVBUFFER_MAX_READ;
}
-#endif
+#endif
if (howmuch < 0 || howmuch > n)
howmuch = n;
diff --git a/libevent/evbuffer.c b/libevent/evbuffer.c
index 52712bce5856..494e45f63e84 100644
--- a/libevent/evbuffer.c
+++ b/libevent/evbuffer.c
@@ -1,3 +1,5 @@
+/* $OpenBSD: evbuffer.c,v 1.10 2007/03/19 15:12:49 millert Exp $ */
+
/*
* Copyright (c) 2002-2004 Niels Provos <provos@citi.umich.edu>
* All rights reserved.
@@ -64,7 +66,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.
*/
@@ -73,7 +75,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.
*/
@@ -288,7 +290,7 @@ bufferevent_free(struct bufferevent *bufev)
*/
int
-bufferevent_write(struct bufferevent *bufev, void *data, size_t size)
+bufferevent_write(struct bufferevent *bufev, const void *data, size_t size)
{
int res;
diff --git a/libevent/event-internal.h b/libevent/event-internal.h
index 7fd4b6c690f3..a6dbe9b1445d 100644
--- a/libevent/event-internal.h
+++ b/libevent/event-internal.h
@@ -1,3 +1,5 @@
+/* $OpenBSD: event-internal.h,v 1.4 2007/03/19 15:12:49 millert Exp $ */
+
/*
* Copyright (c) 2000-2004 Niels Provos <provos@citi.umich.edu>
* All rights reserved.
diff --git a/libevent/event.c b/libevent/event.c
index 15bf14cf3b48..9362e4eca5e3 100644
--- a/libevent/event.c
+++ b/libevent/event.c
@@ -1,3 +1,5 @@
+/* $OpenBSD: event.c,v 1.18 2008/05/02 06:09:11 brad Exp $ */
+
/*
* Copyright (c) 2000-2004 Niels Provos <provos@citi.umich.edu>
* All rights reserved.
@@ -38,7 +40,7 @@
#include <sys/tree.h>
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
-#else
+#else
#include <sys/_time.h>
#endif
#include <sys/queue.h>
@@ -180,7 +182,7 @@ RB_PROTOTYPE(event_tree, event, ev_timeout_node, compare);
RB_GENERATE(event_tree, event, ev_timeout_node, compare);
-void *
+struct event_base *
event_init(void)
{
int i;
@@ -194,13 +196,13 @@ event_init(void)
detect_monotonic();
gettime(&base->event_tv);
-
+
RB_INIT(&base->timetree);
TAILQ_INIT(&base->eventqueue);
TAILQ_INIT(&base->sig.signalqueue);
base->sig.ev_signal_pair[0] = -1;
base->sig.ev_signal_pair[1] = -1;
-
+
base->evbase = NULL;
for (i = 0; eventops[i] && !base->evbase; i++) {
base->evsel = eventops[i];
@@ -321,7 +323,7 @@ event_process_active(struct event_base *base)
for (ev = TAILQ_FIRST(activeq); ev; ev = TAILQ_FIRST(activeq)) {
event_queue_remove(base, ev, EVLIST_ACTIVE);
-
+
/* Allows deletes to work */
ncalls = ev->ev_ncalls;
ev->ev_pncalls = &ncalls;
@@ -430,7 +432,7 @@ event_base_loop(struct event_base *base, int flags)
*/
timerclear(&tv);
}
-
+
/* If we have no events, we just exit */
if (!event_haveevents(base)) {
event_debug(("%s: no events registered.", __func__));
@@ -439,7 +441,6 @@ event_base_loop(struct event_base *base, int flags)
res = evsel->dispatch(base, evbase, tv_p);
-
if (res == -1)
return (-1);
@@ -652,7 +653,7 @@ event_add(struct event *ev, struct timeval *tv)
/* Abort loop */
*ev->ev_pncalls = 0;
}
-
+
event_queue_remove(base, ev, EVLIST_ACTIVE);
}
@@ -913,10 +914,10 @@ event_queue_insert(struct event_base *base, struct event *ev, int queue)
const char *
event_get_version(void)
{
- return (VERSION);
+ return (LIBEVENT_VERSION);
}
-/*
+/*
* No thread-safe interface needed - the information should be the same
* for all threads.
*/
diff --git a/libevent/event.h b/libevent/event.h
index 4c39939cc501..eb16e9044e2d 100644
--- a/libevent/event.h
+++ b/libevent/event.h
@@ -1,3 +1,5 @@
+/* $OpenBSD: event.h,v 1.19 2008/05/02 06:09:11 brad Exp $ */
+
/*
* Copyright (c) 2000-2004 Niels Provos <provos@citi.umich.edu>
* All rights reserved.
@@ -43,6 +45,8 @@ typedef unsigned char u_char;
typedef unsigned short u_short;
#endif
+#define LIBEVENT_VERSION "1.3e"
+
#define EVLIST_TIMEOUT 0x01
#define EVLIST_INSERTED 0x02
#define EVLIST_SIGNAL 0x04
@@ -141,7 +145,7 @@ struct eventop {
void (*dealloc)(struct event_base *, void *);
};
-void *event_init(void);
+struct event_base *event_init(void);
int event_dispatch(void);
int event_base_dispatch(struct event_base *);
void event_base_free(struct event_base *);
@@ -169,12 +173,6 @@ int event_base_loopexit(struct event_base *, struct timeval *);
#define evtimer_pending(ev, tv) event_pending(ev, EV_TIMEOUT, tv)
#define evtimer_initialized(ev) ((ev)->ev_flags & EVLIST_INIT)
-#define timeout_add(ev, tv) event_add(ev, tv)
-#define timeout_set(ev, cb, arg) event_set(ev, -1, 0, cb, arg)
-#define timeout_del(ev) event_del(ev)
-#define timeout_pending(ev, tv) event_pending(ev, EV_TIMEOUT, tv)
-#define timeout_initialized(ev) ((ev)->ev_flags & EVLIST_INIT)
-
#define signal_add(ev, tv) event_add(ev, tv)
#define signal_set(ev, x, cb, arg) \
event_set(ev, x, EV_SIGNAL|EV_PERSIST, cb, arg)
@@ -264,7 +262,8 @@ struct bufferevent *bufferevent_new(int fd,
int bufferevent_base_set(struct event_base *base, struct bufferevent *bufev);
int bufferevent_priority_set(struct bufferevent *bufev, int pri);
void bufferevent_free(struct bufferevent *bufev);
-int bufferevent_write(struct bufferevent *bufev, void *data, size_t size);
+int bufferevent_write(struct bufferevent *bufev,
+ const void *data, size_t size);
int bufferevent_write_buffer(struct bufferevent *bufev, struct evbuffer *buf);
size_t bufferevent_read(struct bufferevent *bufev, void *data, size_t size);
int bufferevent_enable(struct bufferevent *bufev, short event);
@@ -292,7 +291,7 @@ int evbuffer_read(struct evbuffer *, int, int);
u_char *evbuffer_find(struct evbuffer *, const u_char *, size_t);
void evbuffer_setcb(struct evbuffer *, void (*)(struct evbuffer *, size_t, size_t, void *), void *);
-/*
+/*
* Marshaling tagged data - We assume that all tags are inserted in their
* numeric order - so that unknown tags will always be higher than the
* known ones - and we can just ignore the end of an event buffer.
diff --git a/libevent/evsignal.h b/libevent/evsignal.h
index 7efbcabec896..6db8a0577473 100644
--- a/libevent/evsignal.h
+++ b/libevent/evsignal.h
@@ -1,3 +1,5 @@
+/* $OpenBSD: evsignal.h,v 1.2 2004/04/28 06:53:12 brad Exp $ */
+
/*
* Copyright 2000-2002 Niels Provos <provos@citi.umich.edu>
* All rights reserved.
diff --git a/libevent/kqueue.c b/libevent/kqueue.c
index 059d94a0b4d5..6f865f5006e6 100644
--- a/libevent/kqueue.c
+++ b/libevent/kqueue.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kqueue.c,v 1.5 2002/07/10 14:41:31 art Exp $ */
+/* $OpenBSD: kqueue.c,v 1.23 2007/09/02 15:19:18 deraadt Exp $ */
/*
* Copyright 2000-2002 Niels Provos <provos@citi.umich.edu>
@@ -97,14 +97,14 @@ kq_init(struct event_base *base)
struct kqop *kqueueop;
/* Disable kqueue when this environment variable is set */
- if (getenv("EVENT_NOKQUEUE"))
+ if (!issetugid() && getenv("EVENT_NOKQUEUE"))
return (NULL);
if (!(kqueueop = calloc(1, sizeof(struct kqop))))
return (NULL);
/* Initalize the kernel queue */
-
+
if ((kq = kqueue()) == -1) {
event_warn("kqueue");
free (kqueueop);
@@ -114,12 +114,12 @@ kq_init(struct event_base *base)
kqueueop->kq = kq;
/* Initalize fields */
- kqueueop->changes = malloc(NEVENT * sizeof(struct kevent));
+ kqueueop->changes = calloc(NEVENT, sizeof(struct kevent));
if (kqueueop->changes == NULL) {
free (kqueueop);
return (NULL);
}
- kqueueop->events = malloc(NEVENT * sizeof(struct kevent));
+ kqueueop->events = calloc(NEVENT, sizeof(struct kevent));
if (kqueueop->events == NULL) {
free (kqueueop->changes);
free (kqueueop);
@@ -131,7 +131,7 @@ kq_init(struct event_base *base)
kqueueop->changes[0].ident = -1;
kqueueop->changes[0].filter = EVFILT_READ;
kqueueop->changes[0].flags = EV_ADD;
- /*
+ /*
* If kqueue works, then kevent will succeed, and it will
* stick an error in events[0]. If kqueue is broken, then
* kevent will fail.
@@ -195,7 +195,7 @@ kq_insert(struct kqop *kqop, struct kevent *kev)
memcpy(&kqop->changes[kqop->nchanges++], kev, sizeof(struct kevent));
event_debug(("%s: fd %d %s%s",
- __func__, kev->ident,
+ __func__, kev->ident,
kev->filter == EVFILT_READ ? "EVFILT_READ" : "EVFILT_WRITE",
kev->flags == EV_DELETE ? " (del)" : ""));
@@ -241,7 +241,7 @@ kq_dispatch(struct event_base *base, void *arg, struct timeval *tv)
int which = 0;
if (events[i].flags & EV_ERROR) {
- /*
+ /*
* Error messages that can happen, when a delete fails.
* EBADF happens when the file discriptor has been
* closed,
@@ -301,7 +301,7 @@ kq_add(void *arg, struct event *ev)
if (!(ev->ev_events & EV_PERSIST))
kev.flags |= EV_ONESHOT;
kev.udata = PTR_TO_UDATA(ev);
-
+
if (kq_insert(kqop, &kev) == -1)
return (-1);
@@ -324,7 +324,7 @@ kq_add(void *arg, struct event *ev)
if (!(ev->ev_events & EV_PERSIST))
kev.flags |= EV_ONESHOT;
kev.udata = PTR_TO_UDATA(ev);
-
+
if (kq_insert(kqop, &kev) == -1)
return (-1);
@@ -339,7 +339,7 @@ kq_add(void *arg, struct event *ev)
if (!(ev->ev_events & EV_PERSIST))
kev.flags |= EV_ONESHOT;
kev.udata = PTR_TO_UDATA(ev);
-
+
if (kq_insert(kqop, &kev) == -1)
return (-1);
@@ -365,7 +365,7 @@ kq_del(void *arg, struct event *ev)
kev.ident = nsignal;
kev.filter = EVFILT_SIGNAL;
kev.flags = EV_DELETE;
-
+
if (kq_insert(kqop, &kev) == -1)
return (-1);
@@ -381,7 +381,7 @@ kq_del(void *arg, struct event *ev)
kev.ident = ev->ev_fd;
kev.filter = EVFILT_READ;
kev.flags = EV_DELETE;
-
+
if (kq_insert(kqop, &kev) == -1)
return (-1);
@@ -393,7 +393,7 @@ kq_del(void *arg, struct event *ev)
kev.ident = ev->ev_fd;
kev.filter = EVFILT_WRITE;
kev.flags = EV_DELETE;
-
+
if (kq_insert(kqop, &kev) == -1)
return (-1);
diff --git a/libevent/log.c b/libevent/log.c
index c9275e363fc5..95898bd8c131 100644
--- a/libevent/log.c
+++ b/libevent/log.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: err.c,v 1.2 2002/06/25 15:50:15 mickey Exp $ */
+/* $OpenBSD: log.c,v 1.4 2005/05/04 03:17:48 brad Exp $ */
/*
* log.c
@@ -102,7 +102,7 @@ void
event_err(int eval, const char *fmt, ...)
{
va_list ap;
-
+
va_start(ap, fmt);
_warn_helper(_EVENT_LOG_ERR, errno, fmt, ap);
va_end(ap);
@@ -113,7 +113,7 @@ void
event_warn(const char *fmt, ...)
{
va_list ap;
-
+
va_start(ap, fmt);
_warn_helper(_EVENT_LOG_WARN, errno, fmt, ap);
va_end(ap);
@@ -123,7 +123,7 @@ void
event_errx(int eval, const char *fmt, ...)
{
va_list ap;
-
+
va_start(ap, fmt);
_warn_helper(_EVENT_LOG_ERR, -1, fmt, ap);
va_end(ap);
@@ -134,7 +134,7 @@ void
event_warnx(const char *fmt, ...)
{
va_list ap;
-
+
va_start(ap, fmt);
_warn_helper(_EVENT_LOG_WARN, -1, fmt, ap);
va_end(ap);
@@ -144,7 +144,7 @@ void
event_msgx(const char *fmt, ...)
{
va_list ap;
-
+
va_start(ap, fmt);
_warn_helper(_EVENT_LOG_MSG, -1, fmt, ap);
va_end(ap);
@@ -154,7 +154,7 @@ void
_event_debugx(const char *fmt, ...)
{
va_list ap;
-
+
va_start(ap, fmt);
_warn_helper(_EVENT_LOG_DEBUG, -1, fmt, ap);
va_end(ap);
diff --git a/libevent/log.h b/libevent/log.h
index 1f843cf984e0..9acc219d1814 100644
--- a/libevent/log.h
+++ b/libevent/log.h
@@ -1,3 +1,5 @@
+/* $OpenBSD: log.h,v 1.4 2007/03/19 15:12:49 millert Exp $ */
+
/*
* Copyright (c) 2000-2004 Niels Provos <provos@citi.umich.edu>
* All rights reserved.
diff --git a/libevent/poll.c b/libevent/poll.c
index 123d36a56023..b2565c293b5f 100644
--- a/libevent/poll.c
+++ b/libevent/poll.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: poll.c,v 1.2 2002/06/25 15:50:15 mickey Exp $ */
+/* $OpenBSD: poll.c,v 1.13 2006/11/26 15:24:34 brad Exp $ */
/*
* Copyright 2000-2003 Niels Provos <provos@citi.umich.edu>
@@ -89,7 +89,7 @@ poll_init(struct event_base *base)
struct pollop *pollop;
/* Disable poll when this environment variable is set */
- if (getenv("EVENT_NOPOLL"))
+ if (!issetugid() && getenv("EVENT_NOPOLL"))
return (NULL);
if (!(pollop = calloc(1, sizeof(struct pollop))))
@@ -179,6 +179,7 @@ poll_dispatch(struct event_base *base, void *arg, struct timeval *tv)
for (i = 0; i < nfds; i++) {
int what = pop->event_set[i].revents;
struct event *r_ev = NULL, *w_ev = NULL;
+
if (!what)
continue;
@@ -356,7 +357,7 @@ poll_del(void *arg, struct event *ev)
--pop->nfds;
if (i != pop->nfds) {
- /*
+ /*
* Shift the last pollfd down into the now-unoccupied
* position.
*/
diff --git a/libevent/select.c b/libevent/select.c
index d645f1a37030..2cc54ce8aef8 100644
--- a/libevent/select.c
+++ b/libevent/select.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: select.c,v 1.2 2002/06/25 15:50:15 mickey Exp $ */
+/* $OpenBSD: select.c,v 1.13 2007/03/19 15:12:49 millert Exp $ */
/*
* Copyright 2000-2002 Niels Provos <provos@citi.umich.edu>
@@ -96,7 +96,7 @@ select_init(struct event_base *base)
struct selectop *sop;
/* Disable select when this environment variable is set */
- if (getenv("EVENT_NOSELECT"))
+ if (!issetugid() && getenv("EVENT_NOSELECT"))
return (NULL);
if (!(sop = calloc(1, sizeof(struct selectop))))
diff --git a/libevent/signal.c b/libevent/signal.c
index 6c0953d9e121..2364821848f7 100644
--- a/libevent/signal.c
+++ b/libevent/signal.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: select.c,v 1.2 2002/06/25 15:50:15 mickey Exp $ */
+/* $OpenBSD: signal.c,v 1.11 2007/03/19 15:12:49 millert Exp $ */
/*
* Copyright 2000-2002 Niels Provos <provos@citi.umich.edu>
@@ -85,7 +85,7 @@ evsignal_cb(int fd, short what, void *arg)
void
evsignal_init(struct event_base *base)
{
- /*
+ /*
* Our signal handler is going to write to one end of the socket
* pair to wake up our event loop. The event loop then scans for
* signals that got delivered.