summaryrefslogtreecommitdiff
path: root/lib/libevent/kqueue.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libevent/kqueue.c')
-rw-r--r--lib/libevent/kqueue.c63
1 files changed, 29 insertions, 34 deletions
diff --git a/lib/libevent/kqueue.c b/lib/libevent/kqueue.c
index 78309cd6e8d..6280399efe4 100644
--- a/lib/libevent/kqueue.c
+++ b/lib/libevent/kqueue.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kqueue.c,v 1.14 2005/04/19 08:07:45 deraadt Exp $ */
+/* $OpenBSD: kqueue.c,v 1.15 2005/04/22 00:56:25 brad Exp $ */
/*
* Copyright 2000-2002 Niels Provos <provos@citi.umich.edu>
@@ -44,29 +44,18 @@
#include <string.h>
#include <unistd.h>
#include <errno.h>
-#include <err.h>
#ifdef HAVE_INTTYPES_H
#include <inttypes.h>
#endif
-#ifdef USE_LOG
-#include "log.h"
-#else
-#define LOG_DBG(x)
-#define log_error warn
-#endif
-
-#if defined(HAVE_INTTYPES_H) && !defined(__OpenBSD__)
+#if defined(HAVE_INTTYPES_H) && !defined(__OpenBSD__) && !defined(__FreeBSD__)
#define INTPTR(x) (intptr_t)x
#else
#define INTPTR(x) x
#endif
#include "event.h"
-
-extern struct event_list timequeue;
-extern struct event_list eventqueue;
-extern struct event_list addqueue;
+#include "log.h"
#define EVLIST_X_KQINKERNEL 0x1000
@@ -78,13 +67,13 @@ struct kqop {
struct kevent *events;
int nevents;
int kq;
-} kqueueop;
+};
void *kq_init (void);
int kq_add (void *, struct event *);
int kq_del (void *, struct event *);
-int kq_recalc (void *, int);
-int kq_dispatch (void *, struct timeval *);
+int kq_recalc (struct event_base *, void *, int);
+int kq_dispatch (struct event_base *, void *, struct timeval *);
int kq_insert (struct kqop *, struct kevent *);
const struct eventop kqops = {
@@ -100,38 +89,44 @@ void *
kq_init(void)
{
int kq;
+ struct kqop *kqueueop;
/* Disable kqueue when this environment variable is set */
if (!issetugid() && getenv("EVENT_NOKQUEUE"))
return (NULL);
- memset(&kqueueop, 0, sizeof(kqueueop));
+ if (!(kqueueop = calloc(1, sizeof(struct kqop))))
+ return (NULL);
/* Initalize the kernel queue */
if ((kq = kqueue()) == -1) {
- log_error("kqueue");
+ event_warn("kqueue");
+ free (kqueueop);
return (NULL);
}
- kqueueop.kq = kq;
+ kqueueop->kq = kq;
/* Initalize fields */
- kqueueop.changes = malloc(NEVENT * sizeof(struct kevent));
- if (kqueueop.changes == NULL)
+ kqueueop->changes = malloc(NEVENT * sizeof(struct kevent));
+ if (kqueueop->changes == NULL) {
+ free (kqueueop);
return (NULL);
- kqueueop.events = malloc(NEVENT * sizeof(struct kevent));
- if (kqueueop.events == NULL) {
- free (kqueueop.changes);
+ }
+ kqueueop->events = malloc(NEVENT * sizeof(struct kevent));
+ if (kqueueop->events == NULL) {
+ free (kqueueop->changes);
+ free (kqueueop);
return (NULL);
}
- kqueueop.nevents = NEVENT;
+ kqueueop->nevents = NEVENT;
- return (&kqueueop);
+ return (kqueueop);
}
int
-kq_recalc(void *arg, int max)
+kq_recalc(struct event_base *base, void *arg, int max)
{
return (0);
}
@@ -150,7 +145,7 @@ kq_insert(struct kqop *kqop, struct kevent *kev)
newchange = realloc(kqop->changes,
nevents * sizeof(struct kevent));
if (newchange == NULL) {
- log_error("%s: malloc", __func__);
+ event_warn("%s: malloc", __func__);
return (-1);
}
kqop->changes = newchange;
@@ -163,7 +158,7 @@ kq_insert(struct kqop *kqop, struct kevent *kev)
* the next realloc will pick it up.
*/
if (newresult == NULL) {
- log_error("%s: malloc", __func__);
+ event_warn("%s: malloc", __func__);
return (-1);
}
kqop->events = newresult;
@@ -173,7 +168,7 @@ kq_insert(struct kqop *kqop, struct kevent *kev)
memcpy(&kqop->changes[kqop->nchanges++], kev, sizeof(struct kevent));
- LOG_DBG((LOG_MISC, 70, "%s: fd %d %s%s",
+ event_debug(("%s: fd %d %s%s",
__func__, kev->ident,
kev->filter == EVFILT_READ ? "EVFILT_READ" : "EVFILT_WRITE",
kev->flags == EV_DELETE ? " (del)" : ""));
@@ -188,7 +183,7 @@ kq_sighandler(int sig)
}
int
-kq_dispatch(void *arg, struct timeval *tv)
+kq_dispatch(struct event_base *base, void *arg, struct timeval *tv)
{
struct kqop *kqop = arg;
struct kevent *changes = kqop->changes;
@@ -204,14 +199,14 @@ kq_dispatch(void *arg, struct timeval *tv)
kqop->nchanges = 0;
if (res == -1) {
if (errno != EINTR) {
- log_error("kevent");
+ event_warn("kevent");
return (-1);
}
return (0);
}
- LOG_DBG((LOG_MISC, 80, "%s: kevent reports %d", __func__, res));
+ event_debug(("%s: kevent reports %d", __func__, res));
for (i = 0; i < res; i++) {
int which = 0;