From 6ce5b876ea564782600a92ef482485f60d5ae5d5 Mon Sep 17 00:00:00 2001 From: Niels Provos Date: Thu, 12 Jun 2003 23:33:19 +0000 Subject: [PATCH] clean up from NetBSD integration svn:r72 --- event.c | 24 +++++++++++++++++++++++- kqueue.c | 21 +++++++++++---------- poll.c | 8 ++++---- signal.c | 13 +++++++------ 4 files changed, 45 insertions(+), 21 deletions(-) diff --git a/event.c b/event.c index 0376ff58..e5c8cc19 100644 --- a/event.c +++ b/event.c @@ -33,6 +33,12 @@ #include "config.h" #endif +#ifdef WIN32 +#define WIN32_LEAN_AND_MEAN +#include +#undef WIN32_LEAN_AND_MEAN +#include "misc.h" +#endif #include #include #ifdef HAVE_SYS_TIME_H @@ -43,7 +49,9 @@ #include #include #include +#ifndef WIN32 #include +#endif #include #include #include @@ -70,6 +78,9 @@ extern struct eventop epollops; #ifdef HAVE_WORKING_KQUEUE extern struct eventop kqops; #endif +#ifdef WIN32 +extern struct eventop win32ops; +#endif /* In order of preference */ struct eventop *eventops[] = { @@ -84,6 +95,9 @@ struct eventop *eventops[] = { #endif #ifdef HAVE_SELECT &selectops, +#endif +#ifdef WIN32 + &win32ops, #endif NULL }; @@ -98,6 +112,9 @@ int event_gotsig; /* Set in signal handler */ /* Prototypes */ void event_queue_insert(struct event *, int); void event_queue_remove(struct event *, int); +int event_haveevents(void); +void event_process_active(void); +void timeout_insert(struct event *); static RB_HEAD(event_tree, event) timetree; static struct event_list activequeue; @@ -176,7 +193,7 @@ event_process_active(void) while (ncalls) { ncalls--; ev->ev_ncalls = ncalls; - (*ev->ev_callback)(ev->ev_fd, ev->ev_res, ev->ev_arg); + (*ev->ev_callback)((int)ev->ev_fd, ev->ev_res, ev->ev_arg); } } } @@ -259,7 +276,12 @@ event_set(struct event *ev, int fd, short events, { ev->ev_callback = callback; ev->ev_arg = arg; +#ifdef WIN32 + ev->ev_fd = (HANDLE)fd; + ev->overlap.hEvent = ev; +#else ev->ev_fd = fd; +#endif ev->ev_events = events; ev->ev_flags = EVLIST_INIT; ev->ev_ncalls = 0; diff --git a/kqueue.c b/kqueue.c index b0bb9f22..2b00b4c1 100644 --- a/kqueue.c +++ b/kqueue.c @@ -81,13 +81,14 @@ struct kqop { struct kevent *events; int nevents; int kq; -} kqop; +} 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_insert (struct kqop *, struct kevent *); struct eventop kqops = { "kqueue", @@ -107,7 +108,7 @@ kq_init(void) if (getenv("EVENT_NOKQUEUE")) return (NULL); - memset(&kqop, 0, sizeof(kqop)); + memset(&kqueueop, 0, sizeof(kqueueop)); /* Initalize the kernel queue */ @@ -116,20 +117,20 @@ kq_init(void) return (NULL); } - kqop.kq = kq; + kqueueop.kq = kq; /* Initalize fields */ - kqop.changes = malloc(NEVENT * sizeof(struct kevent)); - if (kqop.changes == NULL) + kqueueop.changes = malloc(NEVENT * sizeof(struct kevent)); + if (kqueueop.changes == NULL) return (NULL); - kqop.events = malloc(NEVENT * sizeof(struct kevent)); - if (kqop.events == NULL) { - free (kqop.changes); + kqueueop.events = malloc(NEVENT * sizeof(struct kevent)); + if (kqueueop.events == NULL) { + free (kqueueop.changes); return (NULL); } - kqop.nevents = NEVENT; + kqueueop.nevents = NEVENT; - return (&kqop); + return (&kqueueop); } int diff --git a/poll.c b/poll.c index cda0d394..4806fc2b 100644 --- a/poll.c +++ b/poll.c @@ -68,7 +68,7 @@ struct pollop { struct pollfd *event_set; struct event **event_back; sigset_t evsigmask; -} pop; +} pollop; void *poll_init (void); int poll_add (void *, struct event *); @@ -92,11 +92,11 @@ poll_init(void) if (getenv("EVENT_NOPOLL")) return (NULL); - memset(&pop, 0, sizeof(pop)); + memset(&pollop, 0, sizeof(pollop)); - evsignal_init(&pop.evsigmask); + evsignal_init(&pollop.evsigmask); - return (&pop); + return (&pollop); } /* diff --git a/signal.c b/signal.c index 7fa490ac..c5a3a12e 100644 --- a/signal.c +++ b/signal.c @@ -54,6 +54,7 @@ #endif #include "event.h" +#include "evsignal.h" extern struct event_list signalqueue; @@ -74,12 +75,12 @@ evsignal_init(sigset_t *evsigmask) int evsignal_add(sigset_t *evsigmask, struct event *ev) { - int signal; + int evsignal; if (ev->ev_events & (EV_READ|EV_WRITE)) errx(1, "%s: EV_SIGNAL incompatible use", __func__); - signal = EVENT_SIGNAL(ev); - sigaddset(evsigmask, signal); + evsignal = EVENT_SIGNAL(ev); + sigaddset(evsigmask, evsignal); return (0); } @@ -91,10 +92,10 @@ evsignal_add(sigset_t *evsigmask, struct event *ev) int evsignal_del(sigset_t *evsigmask, struct event *ev) { - int signal; + int evsignal; - signal = EVENT_SIGNAL(ev); - sigdelset(evsigmask, signal); + evsignal = EVENT_SIGNAL(ev); + sigdelset(evsigmask, evsignal); needrecalc = 1; return (sigaction(EVENT_SIGNAL(ev),(struct sigaction *)SIG_DFL, NULL)); -- 2.40.0