comparison src/event/ngx_event.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 e38f51cd0905
comparison
equal deleted inserted replaced
111:a175b609c76d 112:408f195b3482
31 31
32 static void *ngx_event_create_conf(ngx_cycle_t *cycle); 32 static void *ngx_event_create_conf(ngx_cycle_t *cycle);
33 static char *ngx_event_init_conf(ngx_cycle_t *cycle, void *conf); 33 static char *ngx_event_init_conf(ngx_cycle_t *cycle, void *conf);
34 static char *ngx_accept_mutex_check(ngx_conf_t *cf, void *post, void *data); 34 static char *ngx_accept_mutex_check(ngx_conf_t *cf, void *post, void *data);
35 35
36
37 static ngx_uint_t ngx_timer_resolution;
38 sig_atomic_t ngx_event_timer_alarm;
36 39
37 static ngx_uint_t ngx_event_max_module; 40 static ngx_uint_t ngx_event_max_module;
38 41
39 ngx_uint_t ngx_event_flags; 42 ngx_uint_t ngx_event_flags;
40 ngx_event_actions_t ngx_event_actions; 43 ngx_event_actions_t ngx_event_actions;
190 NULL, /* exit master */ 193 NULL, /* exit master */
191 NGX_MODULE_V1_PADDING 194 NGX_MODULE_V1_PADDING
192 }; 195 };
193 196
194 197
198 void
199 ngx_process_events_and_timers(ngx_cycle_t *cycle)
200 {
201 ngx_uint_t flags;
202 ngx_msec_t timer;
203
204 if (ngx_timer_resolution) {
205 timer = NGX_TIMER_INFINITE;
206 flags = 0;
207
208 } else {
209 timer = ngx_event_find_timer();
210 flags = NGX_UPDATE_TIME;
211
212 #if (NGX_THREADS)
213
214 if (timer == NGX_TIMER_INFINITE || timer > 500) {
215 timer = 500;
216 }
217
218 #endif
219 }
220
221 if (ngx_accept_mutex) {
222 if (ngx_accept_disabled > 0) {
223 ngx_accept_disabled--;
224
225 } else {
226 if (ngx_trylock_accept_mutex(cycle) == NGX_ERROR) {
227 return;
228 }
229
230 if (ngx_accept_mutex_held) {
231 flags |= NGX_POST_EVENTS;
232
233 } else {
234 if (timer == NGX_TIMER_INFINITE
235 || timer > ngx_accept_mutex_delay)
236 {
237 timer = ngx_accept_mutex_delay;
238 }
239 }
240 }
241 }
242
243 (void) ngx_process_events(cycle, timer, flags);
244
245 ngx_event_expire_timers();
246
247 if (ngx_posted_accept_events) {
248 ngx_event_process_posted(cycle, &ngx_posted_accept_events);
249 }
250
251 if (ngx_accept_mutex_held) {
252 ngx_accept_mutex = 0;
253 }
254
255 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
256 "posted events %p", ngx_posted_events);
257
258 if (ngx_posted_events) {
259 if (ngx_threaded) {
260 ngx_wakeup_worker_thread(cycle);
261
262 } else {
263 ngx_event_process_posted(cycle, &ngx_posted_events);
264 }
265 }
266 }
267
268
195 ngx_int_t 269 ngx_int_t
196 ngx_handle_read_event(ngx_event_t *rev, u_int flags) 270 ngx_handle_read_event(ngx_event_t *rev, u_int flags)
197 { 271 {
198 if (ngx_event_flags & NGX_USE_CLEAR_EVENT) { 272 if (ngx_event_flags & NGX_USE_CLEAR_EVENT) {
199 273
330 static ngx_int_t 404 static ngx_int_t
331 ngx_event_module_init(ngx_cycle_t *cycle) 405 ngx_event_module_init(ngx_cycle_t *cycle)
332 { 406 {
333 void ***cf; 407 void ***cf;
334 ngx_event_conf_t *ecf; 408 ngx_event_conf_t *ecf;
409 ngx_core_conf_t *ccf;
335 #if !(NGX_WIN32) 410 #if !(NGX_WIN32)
336 char *shared; 411 char *shared;
337 size_t size; 412 size_t size;
338 ngx_int_t limit; 413 ngx_int_t limit;
339 struct rlimit rlmt; 414 struct rlimit rlmt;
340 ngx_core_conf_t *ccf;
341 #endif 415 #endif
342 416
343 cf = ngx_get_conf(cycle->conf_ctx, ngx_events_module); 417 cf = ngx_get_conf(cycle->conf_ctx, ngx_events_module);
344 418
345 if (cf == NULL) { 419 if (cf == NULL) {
351 ecf = (*cf)[ngx_event_core_module.ctx_index]; 425 ecf = (*cf)[ngx_event_core_module.ctx_index];
352 426
353 ngx_log_error(NGX_LOG_NOTICE, cycle->log, 0, 427 ngx_log_error(NGX_LOG_NOTICE, cycle->log, 0,
354 "using the \"%s\" event method", ecf->name); 428 "using the \"%s\" event method", ecf->name);
355 429
430 ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module);
431
432 ngx_timer_resolution = ccf->timer_resolution;
433
356 #if !(NGX_WIN32) 434 #if !(NGX_WIN32)
357
358 ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module);
359 435
360 if (getrlimit(RLIMIT_NOFILE, &rlmt) == -1) { 436 if (getrlimit(RLIMIT_NOFILE, &rlmt) == -1) {
361 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, 437 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
362 "getrlimit(RLIMIT_NOFILE) failed, ignored"); 438 "getrlimit(RLIMIT_NOFILE) failed, ignored");
363 439
415 ngx_stat_reading = (ngx_atomic_t *) (shared + 6 * 128); 491 ngx_stat_reading = (ngx_atomic_t *) (shared + 6 * 128);
416 ngx_stat_writing = (ngx_atomic_t *) (shared + 7 * 128); 492 ngx_stat_writing = (ngx_atomic_t *) (shared + 7 * 128);
417 493
418 #endif 494 #endif
419 495
496 *ngx_connection_counter = 1;
497
420 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, cycle->log, 0, 498 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
421 "counter: %p, %d", 499 "counter: %p, %d",
422 ngx_connection_counter, *ngx_connection_counter); 500 ngx_connection_counter, *ngx_connection_counter);
423 501
424 #endif /* !(NGX_WIN32) */ 502 #endif /* !(NGX_WIN32) */
425 503
426 return NGX_OK; 504 return NGX_OK;
427 } 505 }
506
507
508 #if !(NGX_WIN32)
509
510 void
511 ngx_timer_signal_handler(int signo)
512 {
513 ngx_event_timer_alarm = 1;
514
515 ngx_time_update(0, 0);
516
517 #if 1
518 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, ngx_cycle->log, 0, "timer signal");
519 #endif
520 }
521
522 #endif
428 523
429 524
430 static ngx_int_t 525 static ngx_int_t
431 ngx_event_process_init(ngx_cycle_t *cycle) 526 ngx_event_process_init(ngx_cycle_t *cycle)
432 { 527 {
439 ngx_event_module_t *module; 534 ngx_event_module_t *module;
440 #if (NGX_WIN32) 535 #if (NGX_WIN32)
441 ngx_iocp_conf_t *iocpcf; 536 ngx_iocp_conf_t *iocpcf;
442 #else 537 #else
443 struct rlimit rlmt; 538 struct rlimit rlmt;
539 struct sigaction sa;
540 struct itimerval itv;
444 #endif 541 #endif
445 542
446 ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module); 543 ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module);
447 ecf = ngx_event_get_conf(cycle->conf_ctx, ngx_event_core_module); 544 ecf = ngx_event_get_conf(cycle->conf_ctx, ngx_event_core_module);
448 545
471 continue; 568 continue;
472 } 569 }
473 570
474 if (ngx_modules[m]->ctx_index == ecf->use) { 571 if (ngx_modules[m]->ctx_index == ecf->use) {
475 module = ngx_modules[m]->ctx; 572 module = ngx_modules[m]->ctx;
476 if (module->actions.init(cycle) == NGX_ERROR) { 573 if (module->actions.init(cycle, ngx_timer_resolution) == NGX_ERROR)
574 {
477 /* fatal */ 575 /* fatal */
478 exit(2); 576 exit(2);
479 } 577 }
480 break; 578 break;
481 } 579 }
482 } 580 }
483 581
484 #if !(NGX_WIN32) 582 #if !(NGX_WIN32)
583
584 if (ngx_timer_resolution && !(ngx_event_flags & NGX_USE_TIMER_EVENT)) {
585
586 ngx_memzero(&sa, sizeof(struct sigaction));
587 sa.sa_handler = ngx_timer_signal_handler;
588 sigemptyset(&sa.sa_mask);
589
590 if (sigaction(SIGALRM, &sa, NULL) == -1) {
591 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
592 "sigaction(SIGALRM) failed");
593 return NGX_ERROR;
594 }
595
596 itv.it_interval.tv_sec = ngx_timer_resolution / 1000;
597 itv.it_interval.tv_usec = (ngx_timer_resolution % 1000) * 1000;
598 itv.it_value.tv_sec = ngx_timer_resolution / 1000;
599 itv.it_value.tv_usec = (ngx_timer_resolution % 1000 ) * 1000;
600
601 if (setitimer(ITIMER_REAL, &itv, NULL) == -1) {
602 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
603 "setitimer() failed");
604 }
605 }
485 606
486 if (ngx_event_flags & NGX_USE_FD_EVENT) { 607 if (ngx_event_flags & NGX_USE_FD_EVENT) {
487 608
488 if (getrlimit(RLIMIT_NOFILE, &rlmt) == -1) { 609 if (getrlimit(RLIMIT_NOFILE, &rlmt) == -1) {
489 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, 610 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,