Mercurial > hg > nginx
comparison src/event/modules/ngx_kqueue_module.c @ 86:3973260705cc
nginx-0.0.1-2003-05-12-19:52:24 import
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Mon, 12 May 2003 15:52:24 +0000 |
parents | eacfdd1c31b9 |
children | 5f6d848dcbef |
comparison
equal
deleted
inserted
replaced
85:3549c2bf9eaf | 86:3973260705cc |
---|---|
139 | 139 |
140 ev->active = 0; | 140 ev->active = 0; |
141 | 141 |
142 if (nchanges > 0 | 142 if (nchanges > 0 |
143 && ev->index < nchanges | 143 && ev->index < nchanges |
144 && change_list[ev->index].udata == ev) | 144 && (void *) ((uintptr_t) change_list[ev->index].udata & ~1) == ev) |
145 { | 145 { |
146 #if (NGX_DEBUG_EVENT) | 146 #if (NGX_DEBUG_EVENT) |
147 ngx_connection_t *c = (ngx_connection_t *) ev->data; | 147 ngx_connection_t *c = (ngx_connection_t *) ev->data; |
148 ngx_log_debug(ev->log, "kqueue del event: %d: ft:%d" _ c->fd _ event); | 148 ngx_log_debug(ev->log, "kqueue del event: %d: ft:%d" _ c->fd _ event); |
149 #endif | 149 #endif |
157 } | 157 } |
158 | 158 |
159 return NGX_OK; | 159 return NGX_OK; |
160 } | 160 } |
161 | 161 |
162 /* when a socket is closed kqueue automatically deletes its filters | 162 /* when the file descriptor is closed a kqueue automatically deletes |
163 so we do not need to delete a event explicity before a socket closing */ | 163 its filters so we do not need to delete explicity the event |
164 before the closing the file descriptor */ | |
164 | 165 |
165 if (flags & NGX_CLOSE_EVENT) { | 166 if (flags & NGX_CLOSE_EVENT) { |
166 return NGX_OK; | 167 return NGX_OK; |
167 } | 168 } |
168 | 169 |
198 } | 199 } |
199 | 200 |
200 change_list[nchanges].ident = c->fd; | 201 change_list[nchanges].ident = c->fd; |
201 change_list[nchanges].filter = filter; | 202 change_list[nchanges].filter = filter; |
202 change_list[nchanges].flags = flags; | 203 change_list[nchanges].flags = flags; |
203 change_list[nchanges].udata = ev; | 204 change_list[nchanges].udata = (void *) ((uintptr_t) ev | ev->instance); |
204 | 205 |
205 #if (HAVE_LOWAT_EVENT) | 206 #if (HAVE_LOWAT_EVENT) |
206 | 207 |
207 if ((flags & EV_ADD) && ev->lowat > 0) { | 208 if ((flags & EV_ADD) && ev->lowat > 0) { |
208 change_list[nchanges].fflags = NOTE_LOWAT; | 209 change_list[nchanges].fflags = NOTE_LOWAT; |
228 } | 229 } |
229 | 230 |
230 | 231 |
231 int ngx_kqueue_process_events(ngx_log_t *log) | 232 int ngx_kqueue_process_events(ngx_log_t *log) |
232 { | 233 { |
233 int events, i; | 234 int events, instance, i; |
234 ngx_msec_t timer, delta; | 235 ngx_msec_t timer, delta; |
235 ngx_event_t *ev; | 236 ngx_event_t *ev; |
236 struct timeval tv; | 237 struct timeval tv; |
237 struct timespec ts, *tp; | 238 struct timespec ts, *tp; |
238 | 239 |
308 "kevent error on %d", event_list[i].ident); | 309 "kevent error on %d", event_list[i].ident); |
309 continue; | 310 continue; |
310 } | 311 } |
311 | 312 |
312 ev = (ngx_event_t *) event_list[i].udata; | 313 ev = (ngx_event_t *) event_list[i].udata; |
313 | 314 instance = (uintptr_t) ev & 1; |
314 /* It's a stale event from a socket | 315 ev = (void *) ((uintptr_t) ev & ~1); |
316 | |
317 /* It's a stale event from a file descriptor | |
315 that was just closed in this iteration */ | 318 that was just closed in this iteration */ |
316 | 319 |
317 if (!ev->active) { | 320 if (ev->active == 0 || ev->instance != instance) { |
318 continue; | 321 ngx_log_debug(log, "stale kevent"); |
322 continue; | |
319 } | 323 } |
320 | 324 |
321 switch (event_list[i].filter) { | 325 switch (event_list[i].filter) { |
322 | 326 |
323 case EVFILT_READ: | 327 case EVFILT_READ: |
324 case EVFILT_WRITE: | 328 case EVFILT_WRITE: |
325 | 329 |
326 if (ev->first) { | |
327 if (nchanges > 0 | |
328 && ev->index < nchanges | |
329 && change_list[ev->index].udata == ev) { | |
330 | |
331 /* It's a stale event from a socket that was just closed | |
332 in this iteration and during processing another socket | |
333 was opened with the same number by accept() or socket() | |
334 and its event has been added the event to the change_list | |
335 but has not been passed to a kernel. Nevertheless | |
336 there's small chance that ngx_kqueue_set_event() has | |
337 flushed the new event if the change_list was filled up. | |
338 In this very rare case we would get EAGAIN while | |
339 a reading or a writing */ | |
340 | |
341 continue; | |
342 | |
343 } else { | |
344 ev->first = 0; | |
345 } | |
346 } | |
347 | |
348 ev->available = event_list[i].data; | 330 ev->available = event_list[i].data; |
349 | 331 |
350 if (event_list[i].flags & EV_EOF) { | 332 if (event_list[i].flags & EV_EOF) { |
351 ev->eof = 1; | 333 ev->eof = 1; |
352 ev->error = event_list[i].fflags; | 334 ev->error = event_list[i].fflags; |