| 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 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 free (kqueueop); | 133 free (kqueueop); |
| 134 return (NULL); | 134 return (NULL); |
| 135 } | 135 } |
| 136 kqueueop->nevents = NEVENT; | 136 kqueueop->nevents = NEVENT; |
| 137 | 137 |
| 138 /* we need to keep track of multiple events per signal */ | 138 /* we need to keep track of multiple events per signal */ |
| 139 for (i = 0; i < NSIG; ++i) { | 139 for (i = 0; i < NSIG; ++i) { |
| 140 TAILQ_INIT(&kqueueop->evsigevents[i]); | 140 TAILQ_INIT(&kqueueop->evsigevents[i]); |
| 141 } | 141 } |
| 142 | 142 |
| 143 /* Check for Mac OS X kqueue bug. */ | |
| 144 memset(&kqueueop->changes[0], 0, sizeof kqueueop->changes[0]); | |
| 145 kqueueop->changes[0].ident = -1; | |
| 146 kqueueop->changes[0].filter = EVFILT_READ; | |
| 147 kqueueop->changes[0].flags = EV_ADD; | |
| 148 /* | |
| 149 * If kqueue works, then kevent will succeed, and it will | |
| 150 * stick an error in events[0]. If kqueue is broken, then | |
| 151 * kevent will fail. | |
| 152 */ | |
| 153 if (kevent(kq, | |
| 154 kqueueop->changes, 1, kqueueop->events, NEVENT, NULL) != 1 || | |
| 155 kqueueop->events[0].ident != -1 || | |
| 156 kqueueop->events[0].flags != EV_ERROR) { | |
| 157 event_warn("%s: detected broken kqueue; not using.", __func__); | |
| 158 free(kqueueop->changes); | |
| 159 free(kqueueop->events); | |
| 160 free(kqueueop); | |
| 161 close(kq); | |
| 162 return (NULL); | |
| 163 } | |
| 164 | |
| 165 return (kqueueop); | 143 return (kqueueop); |
| 166 } | 144 } |
| 167 | 145 |
| 168 static int | 146 static int |
| 169 kq_insert(struct kqop *kqop, struct kevent *kev) | 147 kq_insert(struct kqop *kqop, struct kevent *kev) |
| 170 { | 148 { |
| 171 int nevents = kqop->nevents; | 149 int nevents = kqop->nevents; |
| 172 | 150 |
| 173 if (kqop->nchanges == nevents) { | 151 if (kqop->nchanges == nevents) { |
| 174 struct kevent *newchange; | 152 struct kevent *newchange; |
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 446 if (kqop->changes) | 424 if (kqop->changes) |
| 447 free(kqop->changes); | 425 free(kqop->changes); |
| 448 if (kqop->events) | 426 if (kqop->events) |
| 449 free(kqop->events); | 427 free(kqop->events); |
| 450 if (kqop->kq >= 0 && kqop->pid == getpid()) | 428 if (kqop->kq >= 0 && kqop->pid == getpid()) |
| 451 close(kqop->kq); | 429 close(kqop->kq); |
| 452 | 430 |
| 453 memset(kqop, 0, sizeof(struct kqop)); | 431 memset(kqop, 0, sizeof(struct kqop)); |
| 454 free(kqop); | 432 free(kqop); |
| 455 } | 433 } |
| OLD | NEW |