comparison src/core/ngx_cycle.c @ 112:408f195b3482 NGINX_0_3_3

nginx 0.3.3 *) Change: the "bl" and "af" parameters of the "listen" directive was renamed to the "backlog" and "accept_filter". *) Feature: the "rcvbuf" and "sndbuf" parameters of the "listen" directive. *) Change: the "$msec" log parameter does not require now the additional the gettimeofday() system call. *) Feature: the -t switch now tests the "listen" directives. *) Bugfix: if the invalid address was specified in the "listen" directive, then after the -HUP signal nginx left an open socket in the CLOSED state. *) Bugfix: the mime type may be incorrectly set to default value for index file with variable in the name; bug appeared in 0.3.0. *) Feature: the "timer_resolution" directive. *) Feature: the millisecond "$upstream_response_time" log parameter. *) Bugfix: a temporary file with client request body now is removed just after the response header was transferred to a client. *) Bugfix: OpenSSL 0.9.6 compatibility. *) Bugfix: the SSL certificate and key file paths could not be relative. *) Bugfix: the "ssl_prefer_server_ciphers" directive did not work in the ngx_imap_ssl_module. *) Bugfix: the "ssl_protocols" directive allowed to specify the single protocol only.
author Igor Sysoev <http://sysoev.ru>
date Wed, 19 Oct 2005 00:00:00 +0400
parents dad2fe8ecf08
children e85dca77c46a
comparison
equal deleted inserted replaced
111:a175b609c76d 112:408f195b3482
35 #else 35 #else
36 static ngx_str_t error_log = ngx_null_string; 36 static ngx_str_t error_log = ngx_null_string;
37 #endif 37 #endif
38 38
39 39
40 ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle) 40 ngx_cycle_t *
41 ngx_init_cycle(ngx_cycle_t *old_cycle)
41 { 42 {
42 void *rv; 43 void *rv;
43 ngx_uint_t i, n, failed; 44 ngx_uint_t i, n, failed;
44 ngx_log_t *log; 45 ngx_log_t *log;
45 ngx_conf_t conf; 46 ngx_conf_t conf;
46 ngx_pool_t *pool; 47 ngx_pool_t *pool;
47 ngx_cycle_t *cycle, **old; 48 ngx_cycle_t *cycle, **old;
48 ngx_socket_t fd;
49 ngx_list_part_t *part; 49 ngx_list_part_t *part;
50 ngx_open_file_t *file; 50 ngx_open_file_t *file;
51 ngx_listening_t *ls, *nls; 51 ngx_listening_t *ls, *nls;
52 ngx_core_conf_t *ccf; 52 ngx_core_conf_t *ccf;
53 ngx_core_module_t *module; 53 ngx_core_module_t *module;
54 #if (NGX_HAVE_DEFERRED_ACCEPT && defined SO_ACCEPTFILTER)
55 struct accept_filter_arg af;
56 #endif
57 #if (NGX_HAVE_DEFERRED_ACCEPT && defined TCP_DEFER_ACCEPT)
58 int timeout;
59 #endif
60 54
61 log = old_cycle->log; 55 log = old_cycle->log;
62 56
63 pool = ngx_create_pool(NGX_CYCLE_POOL_SIZE, log); 57 pool = ngx_create_pool(NGX_CYCLE_POOL_SIZE, log);
64 if (pool == NULL) { 58 if (pool == NULL) {
313 } 307 }
314 308
315 if (ngx_cmp_sockaddr(nls[n].sockaddr, ls[i].sockaddr) 309 if (ngx_cmp_sockaddr(nls[n].sockaddr, ls[i].sockaddr)
316 == NGX_OK) 310 == NGX_OK)
317 { 311 {
318 fd = ls[i].fd;
319 #if (NGX_WIN32)
320 /*
321 * Winsock assignes a socket number divisible by 4 so
322 * to find a connection we divide a socket number by 4.
323 */
324
325 fd /= 4;
326 #endif
327 if (fd >= (ngx_socket_t) cycle->connection_n) {
328 ngx_log_error(NGX_LOG_EMERG, log, 0,
329 "%d connections is not enough to hold "
330 "an open listening socket on %V, "
331 "required at least %d connections",
332 cycle->connection_n,
333 &ls[i].addr_text, fd);
334 failed = 1;
335 break;
336 }
337
338 nls[n].fd = ls[i].fd; 312 nls[n].fd = ls[i].fd;
339 nls[n].previous = &ls[i]; 313 nls[n].previous = &ls[i];
340 ls[i].remain = 1; 314 ls[i].remain = 1;
341 315
342 if (ls[n].backlog != nls[i].backlog) { 316 if (ls[n].backlog != nls[i].backlog) {
343 nls[n].change_backlog = 1; 317 nls[n].listen = 1;
344 } 318 }
345 319
346 #if (NGX_HAVE_DEFERRED_ACCEPT && defined SO_ACCEPTFILTER) 320 #if (NGX_HAVE_DEFERRED_ACCEPT && defined SO_ACCEPTFILTER)
347 321
348 /* 322 /*
349 * FreeBSD, except the most recent versions, 323 * FreeBSD, except the most recent versions,
350 * can not remove accept filter 324 * could not remove accept filter
351 */ 325 */
352 nls[n].deferred_accept = ls[i].deferred_accept; 326 nls[n].deferred_accept = ls[i].deferred_accept;
353 327
354 if (ls[i].accept_filter && nls[n].accept_filter) { 328 if (ls[i].accept_filter && nls[n].accept_filter) {
355 if (ngx_strcmp(ls[i].accept_filter, 329 if (ngx_strcmp(ls[i].accept_filter,
402 } 376 }
403 #endif 377 #endif
404 } 378 }
405 } 379 }
406 380
407 if (!ngx_test_config && !failed) { 381 if (!failed) {
408 if (ngx_open_listening_sockets(cycle) == NGX_ERROR) { 382 if (ngx_open_listening_sockets(cycle) == NGX_ERROR) {
409 failed = 1; 383 failed = 1;
410 } 384 }
411 385
412 if (!failed) { 386 if (!ngx_test_config && !failed) {
413 ls = cycle->listening.elts; 387 ngx_configure_listening_socket(cycle);
414 for (i = 0; i < cycle->listening.nelts; i++) {
415
416 if (ls[i].change_backlog) {
417 if (listen(ls[i].fd, ls[i].backlog) == -1) {
418 ngx_log_error(NGX_LOG_ALERT, log, ngx_socket_errno,
419 "changing the listen() backlog to %d "
420 "for %V failed, ignored",
421 &ls[i].addr_text, ls[i].backlog);
422 }
423 }
424
425 #if (NGX_HAVE_DEFERRED_ACCEPT)
426
427 #ifdef SO_ACCEPTFILTER
428 if (ls[i].delete_deferred) {
429 if (setsockopt(ls[i].fd, SOL_SOCKET, SO_ACCEPTFILTER,
430 NULL, 0) == -1)
431 {
432 ngx_log_error(NGX_LOG_ALERT, log, ngx_errno,
433 "setsockopt(SO_ACCEPTFILTER, NULL) "
434 "for %V failed, ignored",
435 &ls[i].addr_text);
436
437 if (ls[i].accept_filter) {
438 ngx_log_error(NGX_LOG_ALERT, log, 0,
439 "could not change the accept filter "
440 "to \"%s\" for %V, ignored",
441 ls[i].accept_filter, &ls[i].addr_text);
442 }
443
444 continue;
445 }
446
447 ls[i].deferred_accept = 0;
448 }
449
450 if (ls[i].add_deferred) {
451 ngx_memzero(&af, sizeof(struct accept_filter_arg));
452 (void) ngx_cpystrn((u_char *) af.af_name,
453 (u_char *) ls[i].accept_filter, 16);
454
455 if (setsockopt(ls[i].fd, SOL_SOCKET, SO_ACCEPTFILTER,
456 &af, sizeof(struct accept_filter_arg)) == -1)
457 {
458 ngx_log_error(NGX_LOG_ALERT, log, ngx_errno,
459 "setsockopt(SO_ACCEPTFILTER, \"%s\") "
460 "for %V failed, ignored",
461 ls[i].accept_filter, &ls[i].addr_text);
462 continue;
463 }
464
465 ls[i].deferred_accept = 1;
466 }
467 #endif
468
469 #ifdef TCP_DEFER_ACCEPT
470 if (ls[i].add_deferred || ls[i].delete_deferred) {
471 timeout = 0;
472
473 if (ls[i].add_deferred) {
474 timeout = (int) (ls[i].post_accept_timeout / 1000);
475 }
476
477 if (setsockopt(ls[i].fd, IPPROTO_TCP, TCP_DEFER_ACCEPT,
478 &timeout, sizeof(int)) == -1)
479 {
480 ngx_log_error(NGX_LOG_ALERT, log, ngx_errno,
481 "setsockopt(TCP_DEFER_ACCEPT, %d) "
482 "for %V failed, ignored",
483 timeout, &ls[i].addr_text);
484 continue;
485 }
486 }
487
488 if (ls[i].add_deferred) {
489 ls[i].deferred_accept = 1;
490 }
491 #endif
492 #endif
493 }
494 } 388 }
495 } 389 }
496 } 390 }
497 391
498 if (failed) { 392 if (failed) {
678 572
679 return cycle; 573 return cycle;
680 } 574 }
681 575
682 576
683 static ngx_int_t ngx_cmp_sockaddr(struct sockaddr *sa1, struct sockaddr *sa2) 577 static ngx_int_t
578 ngx_cmp_sockaddr(struct sockaddr *sa1, struct sockaddr *sa2)
684 { 579 {
685 struct sockaddr_in *sin1, *sin2; 580 struct sockaddr_in *sin1, *sin2;
686 581
687 /* AF_INET only */ 582 /* AF_INET only */
688 583
705 } 600 }
706 601
707 602
708 #if !(NGX_WIN32) 603 #if !(NGX_WIN32)
709 604
710 ngx_int_t ngx_create_pidfile(ngx_cycle_t *cycle, ngx_cycle_t *old_cycle) 605 ngx_int_t
606 ngx_create_pidfile(ngx_cycle_t *cycle, ngx_cycle_t *old_cycle)
711 { 607 {
712 ngx_uint_t trunc; 608 ngx_uint_t trunc;
713 size_t len; 609 size_t len;
714 u_char pid[NGX_INT64_LEN]; 610 u_char pid[NGX_INT64_LEN];
715 ngx_file_t file; 611 ngx_file_t file;
774 670
775 return NGX_OK; 671 return NGX_OK;
776 } 672 }
777 673
778 674
779 void ngx_delete_pidfile(ngx_cycle_t *cycle) 675 void
676 ngx_delete_pidfile(ngx_cycle_t *cycle)
780 { 677 {
781 u_char *name; 678 u_char *name;
782 ngx_core_conf_t *ccf; 679 ngx_core_conf_t *ccf;
783 680
784 if (cycle == NULL || cycle->conf_ctx == NULL) { 681 if (cycle == NULL || cycle->conf_ctx == NULL) {
796 } 693 }
797 694
798 #endif 695 #endif
799 696
800 697
801 void ngx_reopen_files(ngx_cycle_t *cycle, ngx_uid_t user) 698 void
699 ngx_reopen_files(ngx_cycle_t *cycle, ngx_uid_t user)
802 { 700 {
803 ngx_fd_t fd; 701 ngx_fd_t fd;
804 ngx_uint_t i; 702 ngx_uint_t i;
805 ngx_list_part_t *part; 703 ngx_list_part_t *part;
806 ngx_open_file_t *file; 704 ngx_open_file_t *file;
934 832
935 #endif 833 #endif
936 } 834 }
937 835
938 836
939 static void ngx_clean_old_cycles(ngx_event_t *ev) 837 static void
838 ngx_clean_old_cycles(ngx_event_t *ev)
940 { 839 {
941 ngx_uint_t i, n, found, live; 840 ngx_uint_t i, n, found, live;
942 ngx_log_t *log; 841 ngx_log_t *log;
943 ngx_cycle_t **cycle; 842 ngx_cycle_t **cycle;
944 843