Mercurial > hg > nginx
comparison src/os/unix/ngx_process_cycle.c @ 563:9c2f3ed7a247 release-0.3.3
nginx-0.3.3-RELEASE import
*) 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; the bug had 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 <igor@sysoev.ru> |
---|---|
date | Wed, 19 Oct 2005 12:33:58 +0000 |
parents | c1f965ef9718 |
children | 458b6c3fea65 |
comparison
equal
deleted
inserted
replaced
562:4b6108f69026 | 563:9c2f3ed7a247 |
---|---|
19 static void ngx_worker_process_cycle(ngx_cycle_t *cycle, void *data); | 19 static void ngx_worker_process_cycle(ngx_cycle_t *cycle, void *data); |
20 static void ngx_worker_process_init(ngx_cycle_t *cycle, ngx_uint_t priority); | 20 static void ngx_worker_process_init(ngx_cycle_t *cycle, ngx_uint_t priority); |
21 static void ngx_channel_handler(ngx_event_t *ev); | 21 static void ngx_channel_handler(ngx_event_t *ev); |
22 #if (NGX_THREADS) | 22 #if (NGX_THREADS) |
23 static void ngx_wakeup_worker_threads(ngx_cycle_t *cycle); | 23 static void ngx_wakeup_worker_threads(ngx_cycle_t *cycle); |
24 static void *ngx_worker_thread_cycle(void *data); | 24 static ngx_thread_value_t ngx_worker_thread_cycle(void *data); |
25 #endif | 25 #endif |
26 #if 0 | 26 #if 0 |
27 static void ngx_garbage_collector_cycle(ngx_cycle_t *cycle, void *data); | 27 static void ngx_garbage_collector_cycle(ngx_cycle_t *cycle, void *data); |
28 #endif | 28 #endif |
29 | 29 |
67 u_char *p; | 67 u_char *p; |
68 size_t size; | 68 size_t size; |
69 ngx_int_t i; | 69 ngx_int_t i; |
70 ngx_uint_t n; | 70 ngx_uint_t n; |
71 sigset_t set; | 71 sigset_t set; |
72 struct timeval tv; | |
73 struct itimerval itv; | 72 struct itimerval itv; |
74 ngx_uint_t live; | 73 ngx_uint_t live; |
75 ngx_msec_t delay; | 74 ngx_msec_t delay; |
76 ngx_listening_t *ls; | 75 ngx_listening_t *ls; |
77 ngx_core_conf_t *ccf; | 76 ngx_core_conf_t *ccf; |
143 | 142 |
144 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0, "sigsuspend"); | 143 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0, "sigsuspend"); |
145 | 144 |
146 sigsuspend(&set); | 145 sigsuspend(&set); |
147 | 146 |
148 ngx_gettimeofday(&tv); | 147 ngx_time_update(0, 0); |
149 ngx_time_update(tv.tv_sec); | |
150 | 148 |
151 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0, "wake up"); | 149 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0, "wake up"); |
152 | 150 |
153 if (ngx_reap) { | 151 if (ngx_reap) { |
154 ngx_reap = 0; | 152 ngx_reap = 0; |
273 } | 271 } |
274 | 272 |
275 for ( ;; ) { | 273 for ( ;; ) { |
276 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0, "worker cycle"); | 274 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0, "worker cycle"); |
277 | 275 |
278 ngx_process_events(cycle); | 276 ngx_process_events_and_timers(cycle); |
279 | 277 |
280 if (ngx_terminate || ngx_quit) { | 278 if (ngx_terminate || ngx_quit) { |
281 ngx_master_exit(cycle); | 279 ngx_master_exit(cycle); |
282 } | 280 } |
283 | 281 |
643 | 641 |
644 | 642 |
645 static void | 643 static void |
646 ngx_worker_process_cycle(ngx_cycle_t *cycle, void *data) | 644 ngx_worker_process_cycle(ngx_cycle_t *cycle, void *data) |
647 { | 645 { |
646 ngx_uint_t i; | |
647 ngx_connection_t *c; | |
648 #if (NGX_THREADS) | 648 #if (NGX_THREADS) |
649 ngx_int_t n; | 649 ngx_int_t n; |
650 ngx_err_t err; | 650 ngx_err_t err; |
651 ngx_core_conf_t *ccf; | 651 ngx_core_conf_t *ccf; |
652 #endif | 652 #endif |
654 ngx_worker_process_init(cycle, 1); | 654 ngx_worker_process_init(cycle, 1); |
655 | 655 |
656 ngx_setproctitle("worker process"); | 656 ngx_setproctitle("worker process"); |
657 | 657 |
658 #if (NGX_THREADS) | 658 #if (NGX_THREADS) |
659 | |
660 if (ngx_time_mutex_init(cycle->log) == NGX_ERROR) { | |
661 /* fatal */ | |
662 exit(2); | |
663 } | |
664 | 659 |
665 ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module); | 660 ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module); |
666 | 661 |
667 if (ngx_threads_n) { | 662 if (ngx_threads_n) { |
668 if (ngx_init_threads(ngx_threads_n, | 663 if (ngx_init_threads(ngx_threads_n, |
729 exit(0); | 724 exit(0); |
730 } | 725 } |
731 | 726 |
732 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0, "worker cycle"); | 727 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0, "worker cycle"); |
733 | 728 |
734 ngx_process_events(cycle); | 729 ngx_process_events_and_timers(cycle); |
735 | 730 |
736 if (ngx_terminate) { | 731 if (ngx_terminate) { |
737 ngx_log_error(NGX_LOG_NOTICE, cycle->log, 0, "exiting"); | 732 ngx_log_error(NGX_LOG_NOTICE, cycle->log, 0, "exiting"); |
738 | 733 |
739 #if (NGX_THREADS) | 734 #if (NGX_THREADS) |
740 ngx_wakeup_worker_threads(cycle); | 735 ngx_wakeup_worker_threads(cycle); |
741 #endif | 736 #endif |
737 | |
738 c = cycle->connections; | |
739 for (i = 0; i < cycle->connection_n; i++) { | |
740 if (c[i].fd != -1 | |
741 && c[i].read | |
742 && !c[i].read->accept | |
743 && !c[i].read->channel) | |
744 { | |
745 ngx_log_error(NGX_LOG_ALERT, cycle->log, 0, | |
746 "open socket #%d left in %ui connection, " | |
747 "aborting", | |
748 c[i].fd, i); | |
749 ngx_abort(); | |
750 } | |
751 } | |
742 | 752 |
743 /* | 753 /* |
744 * we do not destroy cycle->pool here because a signal handler | 754 * we do not destroy cycle->pool here because a signal handler |
745 * that uses cycle->log can be called at this point | 755 * that uses cycle->log can be called at this point |
746 */ | 756 */ |
1052 ngx_sched_yield(); | 1062 ngx_sched_yield(); |
1053 } | 1063 } |
1054 } | 1064 } |
1055 | 1065 |
1056 | 1066 |
1057 static void * | 1067 static ngx_thread_value_t |
1058 ngx_worker_thread_cycle(void *data) | 1068 ngx_worker_thread_cycle(void *data) |
1059 { | 1069 { |
1060 ngx_thread_t *thr = data; | 1070 ngx_thread_t *thr = data; |
1061 | 1071 |
1062 sigset_t set; | 1072 sigset_t set; |
1073 | 1083 |
1074 err = ngx_thread_sigmask(SIG_BLOCK, &set, NULL); | 1084 err = ngx_thread_sigmask(SIG_BLOCK, &set, NULL); |
1075 if (err) { | 1085 if (err) { |
1076 ngx_log_error(NGX_LOG_ALERT, cycle->log, err, | 1086 ngx_log_error(NGX_LOG_ALERT, cycle->log, err, |
1077 ngx_thread_sigmask_n " failed"); | 1087 ngx_thread_sigmask_n " failed"); |
1078 return (void *) 1; | 1088 return (ngx_thread_value_t) 1; |
1079 } | 1089 } |
1080 | 1090 |
1081 ngx_log_debug1(NGX_LOG_DEBUG_CORE, cycle->log, 0, | 1091 ngx_log_debug1(NGX_LOG_DEBUG_CORE, cycle->log, 0, |
1082 "thread " NGX_TID_T_FMT " started", ngx_thread_self()); | 1092 "thread " NGX_TID_T_FMT " started", ngx_thread_self()); |
1083 | 1093 |
1084 ngx_setthrtitle("worker thread"); | 1094 ngx_setthrtitle("worker thread"); |
1085 | 1095 |
1086 tls = ngx_calloc(sizeof(ngx_core_tls_t), cycle->log); | 1096 tls = ngx_calloc(sizeof(ngx_core_tls_t), cycle->log); |
1087 if (tls == NULL) { | 1097 if (tls == NULL) { |
1088 return (void *) 1; | 1098 return (ngx_thread_value_t) 1; |
1089 } | 1099 } |
1090 | 1100 |
1091 err = ngx_thread_set_tls(ngx_core_tls_key, tls); | 1101 err = ngx_thread_set_tls(ngx_core_tls_key, tls); |
1092 if (err != 0) { | 1102 if (err != 0) { |
1093 ngx_log_error(NGX_LOG_ALERT, cycle->log, err, | 1103 ngx_log_error(NGX_LOG_ALERT, cycle->log, err, |
1094 ngx_thread_set_tls_n " failed"); | 1104 ngx_thread_set_tls_n " failed"); |
1095 return (void *) 1; | 1105 return (ngx_thread_value_t) 1; |
1096 } | 1106 } |
1097 | 1107 |
1098 if (ngx_mutex_lock(ngx_posted_events_mutex) == NGX_ERROR) { | 1108 ngx_mutex_lock(ngx_posted_events_mutex); |
1099 return (void *) 1; | |
1100 } | |
1101 | 1109 |
1102 for ( ;; ) { | 1110 for ( ;; ) { |
1103 thr->state = NGX_THREAD_FREE; | 1111 thr->state = NGX_THREAD_FREE; |
1104 | 1112 |
1105 if (ngx_cond_wait(thr->cv, ngx_posted_events_mutex) == NGX_ERROR) { | 1113 if (ngx_cond_wait(thr->cv, ngx_posted_events_mutex) == NGX_ERROR) { |
1106 return (void *) 1; | 1114 return (ngx_thread_value_t) 1; |
1107 } | 1115 } |
1108 | 1116 |
1109 if (ngx_terminate) { | 1117 if (ngx_terminate) { |
1110 thr->state = NGX_THREAD_EXIT; | 1118 thr->state = NGX_THREAD_EXIT; |
1111 | 1119 |
1113 | 1121 |
1114 ngx_log_debug1(NGX_LOG_DEBUG_CORE, cycle->log, 0, | 1122 ngx_log_debug1(NGX_LOG_DEBUG_CORE, cycle->log, 0, |
1115 "thread " NGX_TID_T_FMT " is done", | 1123 "thread " NGX_TID_T_FMT " is done", |
1116 ngx_thread_self()); | 1124 ngx_thread_self()); |
1117 | 1125 |
1118 return (void *) 0; | 1126 return (ngx_thread_value_t) 0; |
1119 } | 1127 } |
1120 | 1128 |
1121 thr->state = NGX_THREAD_BUSY; | 1129 thr->state = NGX_THREAD_BUSY; |
1122 | 1130 |
1123 if (ngx_event_thread_process_posted(cycle) == NGX_ERROR) { | 1131 if (ngx_event_thread_process_posted(cycle) == NGX_ERROR) { |
1124 return (void *) 1; | 1132 return (ngx_thread_value_t) 1; |
1125 } | 1133 } |
1126 | 1134 |
1127 if (ngx_event_thread_process_posted(cycle) == NGX_ERROR) { | 1135 if (ngx_event_thread_process_posted(cycle) == NGX_ERROR) { |
1128 return (void *) 1; | 1136 return (ngx_thread_value_t) 1; |
1129 } | 1137 } |
1130 | 1138 |
1131 if (ngx_process_changes) { | 1139 if (ngx_process_changes) { |
1132 if (ngx_process_changes(cycle, 1) == NGX_ERROR) { | 1140 if (ngx_process_changes(cycle, 1) == NGX_ERROR) { |
1133 return (void *) 1; | 1141 return (ngx_thread_value_t) 1; |
1134 } | 1142 } |
1135 } | 1143 } |
1136 } | 1144 } |
1137 } | 1145 } |
1138 | 1146 |
1183 ngx_collect_garbage(&ctx, &path[i]->name, 0); | 1191 ngx_collect_garbage(&ctx, &path[i]->name, 0); |
1184 } | 1192 } |
1185 | 1193 |
1186 ngx_add_timer(ev, 60 * 60 * 1000); | 1194 ngx_add_timer(ev, 60 * 60 * 1000); |
1187 | 1195 |
1188 ngx_process_events(cycle); | 1196 ngx_process_events_and_timers(cycle); |
1189 } | 1197 } |
1190 } | 1198 } |
1191 | 1199 |
1192 #endif | 1200 #endif |