comparison src/event/modules/ngx_kqueue_module.c @ 326:f70f2f565fe0 NGINX_0_5_33

nginx 0.5.33 *) Change: now by default the "echo" SSI command uses entity encoding. *) Feature: the "encoding" parameter in the "echo" SSI command. *) Change: mail proxy was split on three modules: pop3, imap and smtp. *) Feature: the --without-mail_pop3_module, --without-mail_imap_module, and --without-mail_smtp_module configuration parameters. *) Feature: the "smtp_greeting_delay" and "smtp_client_buffer" directives of the ngx_mail_smtp_module. *) Feature: the "server_name" and "valid_referers" directives support regular expressions. *) Feature: the "server_name", "map", and "valid_referers" directives support the "www.example.*" wildcards. *) Bugfix: sub_filter did not work with empty substitution. *) Bugfix: in sub_filter parsing. *) Bugfix: a worker process may got caught in an endless loop, if the memcached was used. *) Bugfix: nginx supported low case only "close" and "keep-alive" values in the "Connection" request header line; bug appeared in 0.5.32. *) Bugfix: nginx could not start on Solaris if the shared PCRE library located in non-standard place was used.
author Igor Sysoev <http://sysoev.ru>
date Wed, 07 Nov 2007 00:00:00 +0300
parents 7cf404023f50
children
comparison
equal deleted inserted replaced
325:5bb1b28ddeaa 326:f70f2f565fe0
9 #include <ngx_event.h> 9 #include <ngx_event.h>
10 #include <ngx_kqueue_module.h> 10 #include <ngx_kqueue_module.h>
11 11
12 12
13 typedef struct { 13 typedef struct {
14 int changes; 14 ngx_uint_t changes;
15 int events; 15 ngx_uint_t events;
16 } ngx_kqueue_conf_t; 16 } ngx_kqueue_conf_t;
17 17
18 18
19 static ngx_int_t ngx_kqueue_init(ngx_cycle_t *cycle, ngx_msec_t timer); 19 static ngx_int_t ngx_kqueue_init(ngx_cycle_t *cycle, ngx_msec_t timer);
20 static void ngx_kqueue_done(ngx_cycle_t *cycle); 20 static void ngx_kqueue_done(ngx_cycle_t *cycle);
21 static ngx_int_t ngx_kqueue_add_event(ngx_event_t *ev, int event, u_int flags); 21 static ngx_int_t ngx_kqueue_add_event(ngx_event_t *ev, ngx_int_t event,
22 static ngx_int_t ngx_kqueue_del_event(ngx_event_t *ev, int event, u_int flags); 22 ngx_uint_t flags);
23 static ngx_int_t ngx_kqueue_set_event(ngx_event_t *ev, int filter, u_int flags); 23 static ngx_int_t ngx_kqueue_del_event(ngx_event_t *ev, ngx_int_t event,
24 ngx_uint_t flags);
25 static ngx_int_t ngx_kqueue_set_event(ngx_event_t *ev, ngx_int_t filter,
26 ngx_uint_t flags);
24 static ngx_int_t ngx_kqueue_process_changes(ngx_cycle_t *cycle, ngx_uint_t try); 27 static ngx_int_t ngx_kqueue_process_changes(ngx_cycle_t *cycle, ngx_uint_t try);
25 static ngx_int_t ngx_kqueue_process_events(ngx_cycle_t *cycle, ngx_msec_t timer, 28 static ngx_int_t ngx_kqueue_process_events(ngx_cycle_t *cycle, ngx_msec_t timer,
26 ngx_uint_t flags); 29 ngx_uint_t flags);
27 static ngx_inline void ngx_kqueue_dump_event(ngx_log_t *log, 30 static ngx_inline void ngx_kqueue_dump_event(ngx_log_t *log,
28 struct kevent *kev); 31 struct kevent *kev);
41 * readable code. 44 * readable code.
42 */ 45 */
43 46
44 static struct kevent *change_list, *change_list0, *change_list1; 47 static struct kevent *change_list, *change_list0, *change_list1;
45 static struct kevent *event_list; 48 static struct kevent *event_list;
46 static int max_changes, nchanges, nevents; 49 static ngx_uint_t max_changes, nchanges, nevents;
47 50
48 #if (NGX_THREADS) 51 #if (NGX_THREADS)
49 static ngx_mutex_t *list_mutex; 52 static ngx_mutex_t *list_mutex;
50 static ngx_mutex_t *kevent_mutex; 53 static ngx_mutex_t *kevent_mutex;
51 #endif 54 #endif
149 if (max_changes < kcf->changes) { 152 if (max_changes < kcf->changes) {
150 if (nchanges) { 153 if (nchanges) {
151 ts.tv_sec = 0; 154 ts.tv_sec = 0;
152 ts.tv_nsec = 0; 155 ts.tv_nsec = 0;
153 156
154 if (kevent(ngx_kqueue, change_list, nchanges, NULL, 0, &ts) == -1) { 157 if (kevent(ngx_kqueue, change_list, (int) nchanges, NULL, 0, &ts)
158 == -1)
159 {
155 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, 160 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
156 "kevent() failed"); 161 "kevent() failed");
157 return NGX_ERROR; 162 return NGX_ERROR;
158 } 163 }
159 nchanges = 0; 164 nchanges = 0;
271 nevents = 0; 276 nevents = 0;
272 } 277 }
273 278
274 279
275 static ngx_int_t 280 static ngx_int_t
276 ngx_kqueue_add_event(ngx_event_t *ev, int event, u_int flags) 281 ngx_kqueue_add_event(ngx_event_t *ev, ngx_int_t event, ngx_uint_t flags)
277 { 282 {
278 ngx_int_t rc; 283 ngx_int_t rc;
279 #if 0 284 #if 0
280 ngx_event_t *e; 285 ngx_event_t *e;
281 ngx_connection_t *c; 286 ngx_connection_t *c;
287 292
288 ngx_mutex_lock(list_mutex); 293 ngx_mutex_lock(list_mutex);
289 294
290 #if 0 295 #if 0
291 296
292 if (ev->index < (u_int) nchanges 297 if (ev->index < nchanges
293 && ((uintptr_t) change_list[ev->index].udata & (uintptr_t) ~1) 298 && ((uintptr_t) change_list[ev->index].udata & (uintptr_t) ~1)
294 == (uintptr_t) ev) 299 == (uintptr_t) ev)
295 { 300 {
296 if (change_list[ev->index].flags == EV_DISABLE) { 301 if (change_list[ev->index].flags == EV_DISABLE) {
297 302
299 * if the EV_DISABLE is still not passed to a kernel 304 * if the EV_DISABLE is still not passed to a kernel
300 * we will not pass it 305 * we will not pass it
301 */ 306 */
302 307
303 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, ev->log, 0, 308 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, ev->log, 0,
304 "kevent activated: %d: ft:%d", 309 "kevent activated: %d: ft:%i",
305 ngx_event_ident(ev->data), event); 310 ngx_event_ident(ev->data), event);
306 311
307 if (ev->index < (u_int) --nchanges) { 312 if (ev->index < --nchanges) {
308 e = (ngx_event_t *) 313 e = (ngx_event_t *)
309 ((uintptr_t) change_list[nchanges].udata & (uintptr_t) ~1); 314 ((uintptr_t) change_list[nchanges].udata & (uintptr_t) ~1);
310 change_list[ev->index] = change_list[nchanges]; 315 change_list[ev->index] = change_list[nchanges];
311 e->index = ev->index; 316 e->index = ev->index;
312 } 317 }
335 return rc; 340 return rc;
336 } 341 }
337 342
338 343
339 static ngx_int_t 344 static ngx_int_t
340 ngx_kqueue_del_event(ngx_event_t *ev, int event, u_int flags) 345 ngx_kqueue_del_event(ngx_event_t *ev, ngx_int_t event, ngx_uint_t flags)
341 { 346 {
342 ngx_int_t rc; 347 ngx_int_t rc;
343 ngx_event_t *e; 348 ngx_event_t *e;
344 349
345 ev->active = 0; 350 ev->active = 0;
346 ev->disabled = 0; 351 ev->disabled = 0;
347 352
348 ngx_mutex_lock(list_mutex); 353 ngx_mutex_lock(list_mutex);
349 354
350 if (ev->index < (u_int) nchanges 355 if (ev->index < nchanges
351 && ((uintptr_t) change_list[ev->index].udata & (uintptr_t) ~1) 356 && ((uintptr_t) change_list[ev->index].udata & (uintptr_t) ~1)
352 == (uintptr_t) ev) 357 == (uintptr_t) ev)
353 { 358 {
354 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, ev->log, 0, 359 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, ev->log, 0,
355 "kevent deleted: %d: ft:%d", 360 "kevent deleted: %d: ft:%i",
356 ngx_event_ident(ev->data), event); 361 ngx_event_ident(ev->data), event);
357 362
358 /* if the event is still not passed to a kernel we will not pass it */ 363 /* if the event is still not passed to a kernel we will not pass it */
359 364
360 nchanges--; 365 nchanges--;
361 366
362 if (ev->index < (u_int) nchanges) { 367 if (ev->index < nchanges) {
363 e = (ngx_event_t *) 368 e = (ngx_event_t *)
364 ((uintptr_t) change_list[nchanges].udata & (uintptr_t) ~1); 369 ((uintptr_t) change_list[nchanges].udata & (uintptr_t) ~1);
365 change_list[ev->index] = change_list[nchanges]; 370 change_list[ev->index] = change_list[nchanges];
366 e->index = ev->index; 371 e->index = ev->index;
367 } 372 }
394 return rc; 399 return rc;
395 } 400 }
396 401
397 402
398 static ngx_int_t 403 static ngx_int_t
399 ngx_kqueue_set_event(ngx_event_t *ev, int filter, u_int flags) 404 ngx_kqueue_set_event(ngx_event_t *ev, ngx_int_t filter, ngx_uint_t flags)
400 { 405 {
401 struct kevent *kev; 406 struct kevent *kev;
402 struct timespec ts; 407 struct timespec ts;
403 ngx_connection_t *c; 408 ngx_connection_t *c;
404 409
405 c = ev->data; 410 c = ev->data;
406 411
407 ngx_log_debug3(NGX_LOG_DEBUG_EVENT, ev->log, 0, 412 ngx_log_debug3(NGX_LOG_DEBUG_EVENT, ev->log, 0,
408 "kevent set event: %d: ft:%d fl:%04Xd", 413 "kevent set event: %d: ft:%i fl:%04Xi",
409 c->fd, filter, flags); 414 c->fd, filter, flags);
410 415
411 if (nchanges >= max_changes) { 416 if (nchanges >= max_changes) {
412 ngx_log_error(NGX_LOG_WARN, ev->log, 0, 417 ngx_log_error(NGX_LOG_WARN, ev->log, 0,
413 "kqueue change list is filled up"); 418 "kqueue change list is filled up");
414 419
415 ts.tv_sec = 0; 420 ts.tv_sec = 0;
416 ts.tv_nsec = 0; 421 ts.tv_nsec = 0;
417 422
418 if (kevent(ngx_kqueue, change_list, nchanges, NULL, 0, &ts) == -1) { 423 if (kevent(ngx_kqueue, change_list, (int) nchanges, NULL, 0, &ts)
424 == -1)
425 {
419 ngx_log_error(NGX_LOG_ALERT, ev->log, ngx_errno, "kevent() failed"); 426 ngx_log_error(NGX_LOG_ALERT, ev->log, ngx_errno, "kevent() failed");
420 return NGX_ERROR; 427 return NGX_ERROR;
421 } 428 }
422 429
423 nchanges = 0; 430 nchanges = 0;
424 } 431 }
425 432
426 kev = &change_list[nchanges]; 433 kev = &change_list[nchanges];
427 434
428 kev->ident = c->fd; 435 kev->ident = c->fd;
429 kev->filter = filter; 436 kev->filter = (short) filter;
430 kev->flags = flags; 437 kev->flags = (u_short) flags;
431 kev->udata = NGX_KQUEUE_UDATA_T ((uintptr_t) ev | ev->instance); 438 kev->udata = NGX_KQUEUE_UDATA_T ((uintptr_t) ev | ev->instance);
432 439
433 if (filter == EVFILT_VNODE) { 440 if (filter == EVFILT_VNODE) {
434 kev->fflags = NOTE_DELETE|NOTE_WRITE|NOTE_EXTEND 441 kev->fflags = NOTE_DELETE|NOTE_WRITE|NOTE_EXTEND
435 |NOTE_ATTRIB|NOTE_RENAME 442 |NOTE_ATTRIB|NOTE_RENAME
480 } 487 }
481 488
482 n = 0; 489 n = 0;
483 490
484 } else { 491 } else {
485 n = nchanges; 492 n = (int) nchanges;
486 nchanges = 0; 493 nchanges = 0;
487 } 494 }
488 495
489 if (timer == NGX_TIMER_INFINITE) { 496 if (timer == NGX_TIMER_INFINITE) {
490 tp = NULL; 497 tp = NULL;
508 } 515 }
509 516
510 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, cycle->log, 0, 517 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
511 "kevent timer: %M, changes: %d", timer, n); 518 "kevent timer: %M, changes: %d", timer, n);
512 519
513 events = kevent(ngx_kqueue, change_list, n, event_list, nevents, tp); 520 events = kevent(ngx_kqueue, change_list, n, event_list, (int) nevents, tp);
514 521
515 if (events == -1) { 522 if (events == -1) {
516 err = ngx_errno; 523 err = ngx_errno;
517 } else { 524 } else {
518 err = 0; 525 err = 0;
694 change_list = change_list1; 701 change_list = change_list1;
695 } else { 702 } else {
696 change_list = change_list0; 703 change_list = change_list0;
697 } 704 }
698 705
699 n = nchanges; 706 n = (int) nchanges;
700 nchanges = 0; 707 nchanges = 0;
701 708
702 ngx_mutex_unlock(list_mutex); 709 ngx_mutex_unlock(list_mutex);
703 710
704 ts.tv_sec = 0; 711 ts.tv_sec = 0;
756 static char * 763 static char *
757 ngx_kqueue_init_conf(ngx_cycle_t *cycle, void *conf) 764 ngx_kqueue_init_conf(ngx_cycle_t *cycle, void *conf)
758 { 765 {
759 ngx_kqueue_conf_t *kcf = conf; 766 ngx_kqueue_conf_t *kcf = conf;
760 767
761 ngx_conf_init_value(kcf->changes, 512); 768 ngx_conf_init_uint_value(kcf->changes, 512);
762 ngx_conf_init_value(kcf->events, 512); 769 ngx_conf_init_uint_value(kcf->events, 512);
763 770
764 return NGX_CONF_OK; 771 return NGX_CONF_OK;
765 } 772 }