| OLD | NEW |
| 1 /* $OpenBSD: kqueue.c,v 1.5 2002/07/10 14:41:31 art Exp $ */ | 1 /* $OpenBSD: kqueue.c,v 1.5 2002/07/10 14:41:31 art Exp $ */ |
| 2 | 2 |
| 3 /* | 3 /* |
| 4 * Copyright 2000-2002 Niels Provos <provos@citi.umich.edu> | 4 * Copyright 2000-2002 Niels Provos <provos@citi.umich.edu> |
| 5 * All rights reserved. | 5 * All rights reserved. |
| 6 * | 6 * |
| 7 * Redistribution and use in source and binary forms, with or without | 7 * Redistribution and use in source and binary forms, with or without |
| 8 * modification, are permitted provided that the following conditions | 8 * modification, are permitted provided that the following conditions |
| 9 * are met: | 9 * are met: |
| 10 * 1. Redistributions of source code must retain the above copyright | 10 * 1. Redistributions of source code must retain the above copyright |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | 26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 */ | 28 */ |
| 29 #ifdef HAVE_CONFIG_H | 29 #ifdef HAVE_CONFIG_H |
| 30 #include "config.h" | 30 #include "config.h" |
| 31 #endif | 31 #endif |
| 32 | 32 |
| 33 #define _GNU_SOURCE 1 |
| 34 |
| 33 #include <sys/types.h> | 35 #include <sys/types.h> |
| 34 #ifdef HAVE_SYS_TIME_H | 36 #ifdef HAVE_SYS_TIME_H |
| 35 #include <sys/time.h> | 37 #include <sys/time.h> |
| 36 #else | 38 #else |
| 37 #include <sys/_time.h> | 39 #include <sys/_libevent_time.h> |
| 38 #endif | 40 #endif |
| 39 #include <sys/queue.h> | 41 #include <sys/queue.h> |
| 40 #include <sys/event.h> | 42 #include <sys/event.h> |
| 41 #include <signal.h> | 43 #include <signal.h> |
| 42 #include <stdio.h> | 44 #include <stdio.h> |
| 43 #include <stdlib.h> | 45 #include <stdlib.h> |
| 44 #include <string.h> | 46 #include <string.h> |
| 45 #include <unistd.h> | 47 #include <unistd.h> |
| 46 #include <errno.h> | 48 #include <errno.h> |
| 47 #include <assert.h> | 49 #include <assert.h> |
| 48 #ifdef HAVE_INTTYPES_H | 50 #ifdef HAVE_INTTYPES_H |
| 49 #include <inttypes.h> | 51 #include <inttypes.h> |
| 50 #endif | 52 #endif |
| 51 | 53 |
| 52 /* Some platforms apparently define the udata field of struct kevent as | 54 /* Some platforms apparently define the udata field of struct kevent as |
| 53 * intptr_t, whereas others define it as void*. There doesn't seem to be an | 55 * intptr_t, whereas others define it as void*. There doesn't seem to be an |
| 54 * easy way to tell them apart via autoconf, so we need to use OS macros. */ | 56 * easy way to tell them apart via autoconf, so we need to use OS macros. */ |
| 55 #if defined(HAVE_INTTYPES_H) && !defined(__OpenBSD__) && !defined(__FreeBSD__) &
& !defined(__darwin__) && !defined(__APPLE__) | 57 #if defined(HAVE_INTTYPES_H) && !defined(__OpenBSD__) && !defined(__FreeBSD__) &
& !defined(__darwin__) && !defined(__APPLE__) |
| 56 #define PTR_TO_UDATA(x) ((intptr_t)(x)) | 58 #define PTR_TO_UDATA(x) ((intptr_t)(x)) |
| 57 #else | 59 #else |
| 58 #define PTR_TO_UDATA(x) (x) | 60 #define PTR_TO_UDATA(x) (x) |
| 59 #endif | 61 #endif |
| 60 | 62 |
| 61 #include "event.h" | 63 #include "event.h" |
| 62 #include "event-internal.h" | 64 #include "event-internal.h" |
| 63 #include "log.h" | 65 #include "log.h" |
| 64 #include "event-internal.h" | |
| 65 | 66 |
| 66 #define EVLIST_X_KQINKERNEL 0x1000 | 67 #define EVLIST_X_KQINKERNEL 0x1000 |
| 67 | 68 |
| 68 #define NEVENT 64 | 69 #define NEVENT 64 |
| 69 | 70 |
| 70 struct kqop { | 71 struct kqop { |
| 71 struct kevent *changes; | 72 struct kevent *changes; |
| 72 int nchanges; | 73 int nchanges; |
| 73 struct kevent *events; | 74 struct kevent *events; |
| 74 struct event_list evsigevents[NSIG]; | 75 struct event_list evsigevents[NSIG]; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 94 1 /* need reinit */ | 95 1 /* need reinit */ |
| 95 }; | 96 }; |
| 96 | 97 |
| 97 static void * | 98 static void * |
| 98 kq_init(struct event_base *base) | 99 kq_init(struct event_base *base) |
| 99 { | 100 { |
| 100 int i, kq; | 101 int i, kq; |
| 101 struct kqop *kqueueop; | 102 struct kqop *kqueueop; |
| 102 | 103 |
| 103 /* Disable kqueue when this environment variable is set */ | 104 /* Disable kqueue when this environment variable is set */ |
| 104 » if (getenv("EVENT_NOKQUEUE")) | 105 » if (evutil_getenv("EVENT_NOKQUEUE")) |
| 105 return (NULL); | 106 return (NULL); |
| 106 | 107 |
| 107 if (!(kqueueop = calloc(1, sizeof(struct kqop)))) | 108 if (!(kqueueop = calloc(1, sizeof(struct kqop)))) |
| 108 return (NULL); | 109 return (NULL); |
| 109 | 110 |
| 110 /* Initalize the kernel queue */ | 111 /* Initalize the kernel queue */ |
| 111 | 112 |
| 112 if ((kq = kqueue()) == -1) { | 113 if ((kq = kqueue()) == -1) { |
| 113 event_warn("kqueue"); | 114 event_warn("kqueue"); |
| 114 free (kqueueop); | 115 free (kqueueop); |
| (...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 440 | 441 |
| 441 if (kqop->changes) | 442 if (kqop->changes) |
| 442 free(kqop->changes); | 443 free(kqop->changes); |
| 443 if (kqop->events) | 444 if (kqop->events) |
| 444 free(kqop->events); | 445 free(kqop->events); |
| 445 if (kqop->kq >= 0 && kqop->pid == getpid()) | 446 if (kqop->kq >= 0 && kqop->pid == getpid()) |
| 446 close(kqop->kq); | 447 close(kqop->kq); |
| 447 memset(kqop, 0, sizeof(struct kqop)); | 448 memset(kqop, 0, sizeof(struct kqop)); |
| 448 free(kqop); | 449 free(kqop); |
| 449 } | 450 } |
| OLD | NEW |