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. */ | 143 /* Check for Mac OS X kqueue bug. */ |
Mark Mentovai
2016/07/08 11:15:02
Since we’ve already got a bunch of local modificat
erikchen
2016/07/08 15:20:06
Done.
| |
144 memset(&kqueueop->changes[0], 0, sizeof kqueueop->changes[0]); | 144 memset(&kqueueop->changes[0], 0, sizeof kqueueop->changes[0]); |
145 kqueueop->changes[0].ident = -1; | 145 kqueueop->changes[0].ident = -1; |
146 kqueueop->changes[0].filter = EVFILT_READ; | 146 kqueueop->changes[0].filter = EVFILT_READ; |
147 kqueueop->changes[0].flags = EV_ADD; | 147 kqueueop->changes[0].flags = EV_ADD; |
148 /* | 148 /* |
149 * If kqueue works, then kevent will succeed, and it will | 149 * If kqueue works, then kevent will succeed, and it will |
150 * stick an error in events[0]. If kqueue is broken, then | 150 * stick an error in events[0]. If kqueue is broken, then |
151 * kevent will fail. | 151 * kevent will fail. |
152 */ | 152 */ |
153 if (kevent(kq, | 153 if (kevent(kq, |
154 kqueueop->changes, 1, kqueueop->events, NEVENT, NULL) != 1 || | 154 kqueueop->changes, 1, kqueueop->events, NEVENT, NULL) != 1 || |
155 kqueueop->events[0].ident != -1 || | 155 kqueueop->events[0].ident != -1 || |
156 » kqueueop->events[0].flags != EV_ERROR) { | 156 » !(kqueueop->events[0].flags & EV_ERROR)) { |
157 event_warn("%s: detected broken kqueue; not using.", __func__); | 157 event_warn("%s: detected broken kqueue; not using.", __func__); |
158 free(kqueueop->changes); | 158 free(kqueueop->changes); |
159 free(kqueueop->events); | 159 free(kqueueop->events); |
160 free(kqueueop); | 160 free(kqueueop); |
161 close(kq); | 161 close(kq); |
162 return (NULL); | 162 return (NULL); |
163 } | 163 } |
164 | 164 |
165 return (kqueueop); | 165 return (kqueueop); |
166 } | 166 } |
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
446 if (kqop->changes) | 446 if (kqop->changes) |
447 free(kqop->changes); | 447 free(kqop->changes); |
448 if (kqop->events) | 448 if (kqop->events) |
449 free(kqop->events); | 449 free(kqop->events); |
450 if (kqop->kq >= 0 && kqop->pid == getpid()) | 450 if (kqop->kq >= 0 && kqop->pid == getpid()) |
451 close(kqop->kq); | 451 close(kqop->kq); |
452 | 452 |
453 memset(kqop, 0, sizeof(struct kqop)); | 453 memset(kqop, 0, sizeof(struct kqop)); |
454 free(kqop); | 454 free(kqop); |
455 } | 455 } |
OLD | NEW |