Mercurial > hg > nginx
diff src/event/modules/ngx_rtsig_module.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 | 1af2fcb3be8a |
line wrap: on
line diff
--- a/src/event/modules/ngx_rtsig_module.c Wed Oct 12 13:50:36 2005 +0000 +++ b/src/event/modules/ngx_rtsig_module.c Wed Oct 19 12:33:58 2005 +0000 @@ -38,12 +38,14 @@ extern ngx_event_module_t ngx_poll_module_ctx; -static ngx_int_t ngx_rtsig_init(ngx_cycle_t *cycle); +static ngx_int_t ngx_rtsig_init(ngx_cycle_t *cycle, ngx_msec_t timer); static void ngx_rtsig_done(ngx_cycle_t *cycle); static ngx_int_t ngx_rtsig_add_connection(ngx_connection_t *c); static ngx_int_t ngx_rtsig_del_connection(ngx_connection_t *c, u_int flags); -static ngx_int_t ngx_rtsig_process_events(ngx_cycle_t *cycle); -static ngx_int_t ngx_rtsig_process_overflow(ngx_cycle_t *cycle); +static ngx_int_t ngx_rtsig_process_events(ngx_cycle_t *cycle, + ngx_msec_t timer, ngx_uint_t flags); +static ngx_int_t ngx_rtsig_process_overflow(ngx_cycle_t *cycle, + ngx_msec_t timer, ngx_uint_t flags); static void *ngx_rtsig_create_conf(ngx_cycle_t *cycle); static char *ngx_rtsig_init_conf(ngx_cycle_t *cycle, void *conf); @@ -134,7 +136,7 @@ static ngx_int_t -ngx_rtsig_init(ngx_cycle_t *cycle) +ngx_rtsig_init(ngx_cycle_t *cycle, ngx_msec_t timer) { ngx_rtsig_conf_t *rtscf; @@ -144,6 +146,7 @@ sigaddset(&set, rtscf->signo); sigaddset(&set, rtscf->signo + 1); sigaddset(&set, SIGIO); + sigaddset(&set, SIGALRM); if (sigprocmask(SIG_BLOCK, &set, NULL) == -1) { ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, @@ -279,59 +282,19 @@ static ngx_int_t -ngx_rtsig_process_events(ngx_cycle_t *cycle) +ngx_rtsig_process_events(ngx_cycle_t *cycle, ngx_msec_t timer, ngx_uint_t flags) { int signo; ngx_int_t instance; - ngx_msec_t timer, delta; + ngx_msec_t delta; ngx_err_t err; siginfo_t si; ngx_event_t *rev, *wev; - struct timeval tv; struct timespec ts, *tp; struct sigaction sa; ngx_connection_t *c; ngx_rtsig_conf_t *rtscf; - if (overflow) { - timer = 0; - - } else { - timer = ngx_event_find_timer(); - -#if (NGX_THREADS) - - if (timer == NGX_TIMER_ERROR) { - return NGX_ERROR; - } - - if (timer == NGX_TIMER_INFINITE || timer > 500) { - timer = 500; - } - -#endif - - if (ngx_accept_mutex) { - if (ngx_accept_disabled > 0) { - ngx_accept_disabled--; - - } else { - ngx_accept_mutex_held = 0; - - if (ngx_trylock_accept_mutex(cycle) == NGX_ERROR) { - return NGX_ERROR; - } - - if (ngx_accept_mutex_held == 0 - && (timer == NGX_TIMER_INFINITE - || timer > ngx_accept_mutex_delay)) - { - timer = ngx_accept_mutex_delay; - } - } - } - } - if (timer == NGX_TIMER_INFINITE) { tp = NULL; @@ -357,7 +320,6 @@ if (err == NGX_EAGAIN) { if (timer == NGX_TIMER_INFINITE) { - ngx_accept_mutex_unlock(); ngx_log_error(NGX_LOG_ALERT, cycle->log, err, "sigtimedwait() returned EAGAIN without timeout"); return NGX_ERROR; @@ -373,21 +335,20 @@ signo, si.si_fd, si.si_band); } - ngx_gettimeofday(&tv); - ngx_time_update(tv.tv_sec); - - delta = ngx_current_time; - ngx_current_time = (ngx_msec_t) tv.tv_sec * 1000 + tv.tv_usec / 1000; + delta = ngx_current_msec; + + if (flags & NGX_UPDATE_TIME) { + ngx_time_update(0, 0); + } if (err) { - ngx_accept_mutex_unlock(); ngx_log_error((err == NGX_EINTR) ? NGX_LOG_INFO : NGX_LOG_ALERT, cycle->log, err, "sigtimedwait() failed"); return NGX_ERROR; } if (timer != NGX_TIMER_INFINITE) { - delta = ngx_current_time - delta; + delta = ngx_current_msec - delta; ngx_log_debug2(NGX_LOG_DEBUG_EVENT, cycle->log, 0, "rtsig timer: %M, delta: %M", timer, delta); @@ -404,10 +365,9 @@ c = ngx_cycle->files[si.si_fd]; if (c == NULL) { + /* the stale event */ - ngx_accept_mutex_unlock(); - return NGX_OK; } @@ -415,84 +375,36 @@ rev = c->read; - if (c->read->instance != instance) { + if (rev->instance != instance) { /* * the stale event from a file descriptor * that was just closed in this iteration */ - ngx_accept_mutex_unlock(); - ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0, "rtsig: stale event %p", c); return NGX_OK; } - if (si.si_band & (POLLIN|POLLHUP|POLLERR)) { - if (rev->active) { - - if (ngx_threaded && !rev->accept) { - if (ngx_mutex_lock(ngx_posted_events_mutex) == NGX_ERROR) { - ngx_accept_mutex_unlock(); - return NGX_ERROR; - } - - rev->posted_ready = 1; - ngx_post_event(rev); - - ngx_mutex_unlock(ngx_posted_events_mutex); - - } else { - rev->ready = 1; - - if (!ngx_threaded && !ngx_accept_mutex_held) { - rev->handler(rev); - - } else if (rev->accept) { - if (ngx_accept_disabled <= 0) { - rev->handler(rev); - } - - } else { - ngx_post_event(rev); - } - } - } + if ((si.si_band & (POLLIN|POLLHUP|POLLERR)) && rev->active) { + rev->ready = 1; + rev->handler(rev); } wev = c->write; - if (si.si_band & (POLLOUT|POLLHUP|POLLERR)) { - if (wev->active) { - - if (ngx_threaded) { - if (ngx_mutex_lock(ngx_posted_events_mutex) == NGX_ERROR) { - ngx_accept_mutex_unlock(); - return NGX_ERROR; - } - - wev->posted_ready = 1; - ngx_post_event(wev); - - ngx_mutex_unlock(ngx_posted_events_mutex); - - } else { - wev->ready = 1; - - if (!ngx_threaded && !ngx_accept_mutex_held) { - wev->handler(wev); - - } else { - ngx_post_event(wev); - } - } - } + if ((si.si_band & (POLLOUT|POLLHUP|POLLERR)) && wev->active) { + wev->ready = 1; + wev->handler(wev); } + } else if (signo == SIGALRM) { + + return NGX_OK; + } else if (signo == SIGIO) { - ngx_accept_mutex_unlock(); ngx_log_error(NGX_LOG_ALERT, cycle->log, 0, "rt signal queue overflowed"); @@ -520,48 +432,35 @@ return NGX_ERROR; } else if (signo != -1) { - ngx_accept_mutex_unlock(); - ngx_log_error(NGX_LOG_ALERT, cycle->log, 0, "sigtimedwait() returned unexpected signal: %d", signo); return NGX_ERROR; } - ngx_accept_mutex_unlock(); - - ngx_event_expire_timers(); - - if (ngx_posted_events) { - if (ngx_threaded) { - ngx_wakeup_worker_thread(cycle); - - } else { - ngx_event_process_posted(cycle); - } + if (signo != -1) { + return NGX_OK; } - if (signo == -1) { - return NGX_AGAIN; - } else { - return NGX_OK; - } + return NGX_AGAIN; } -/* TODO: old cylces */ - static ngx_int_t -ngx_rtsig_process_overflow(ngx_cycle_t *cycle) +ngx_rtsig_process_overflow(ngx_cycle_t *cycle, ngx_msec_t timer, + ngx_uint_t flags) { int name[2], rtsig_max, rtsig_nr, events, ready; size_t len; ngx_int_t tested, n, i; ngx_err_t err; - ngx_event_t *rev, *wev; + ngx_event_t *rev, *wev, **queue; ngx_connection_t *c; ngx_rtsig_conf_t *rtscf; + ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0, + "rtsig process overflow"); + rtscf = ngx_event_get_conf(ngx_cycle->conf_ctx, ngx_rtsig_module); tested = 0; @@ -608,6 +507,9 @@ for ( ;; ) { ready = poll(overflow_list, n, 0); + ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0, + "rtsig overflow poll:%d", ready); + if (ready == -1) { err = ngx_errno; ngx_log_error((err == NGX_EINTR) ? NGX_LOG_INFO : NGX_LOG_ALERT, @@ -626,9 +528,7 @@ continue; } - if (ngx_mutex_lock(ngx_posted_events_mutex) == NGX_ERROR) { - return NGX_ERROR; - } + ngx_mutex_lock(ngx_posted_events_mutex); for (i = 0; i < n; i++) { c = cycle->files[overflow_list[i].fd]; @@ -647,13 +547,21 @@ { tested++; - if (ngx_threaded) { + if ((flags & NGX_POST_THREAD_EVENTS) && !rev->accept) { rev->posted_ready = 1; - ngx_post_event(rev); } else { rev->ready = 1; - rev->handler(rev); + } + + if (flags & NGX_POST_EVENTS) { + queue = (ngx_event_t **) (rev->accept ? + &ngx_posted_accept_events : &ngx_posted_events); + + ngx_locked_post_event(rev, queue); + + } else { + rev->handler(rev); } } @@ -667,13 +575,18 @@ { tested++; - if (ngx_threaded) { + if (flags & NGX_POST_THREAD_EVENTS) { wev->posted_ready = 1; - ngx_post_event(wev); } else { wev->ready = 1; - wev->handler(wev); + } + + if (flags & NGX_POST_EVENTS) { + ngx_locked_post_event(wev, &ngx_posted_events); + + } else { + wev->handler(wev); } } } @@ -688,8 +601,8 @@ * Check the current rt queue length to prevent * the new overflow. * - * Learn the /proc/sys/kernel/rtsig-max value because - * it can be changed since the last checking. + * learn the "/proc/sys/kernel/rtsig-max" value because + * it can be changed since the last checking */ name[0] = CTL_KERN; @@ -713,16 +626,17 @@ } /* - * drain the rt signal queue if the /proc/sys/kernel/rtsig-nr + * drain the rt signal queue if the /"proc/sys/kernel/rtsig-nr" * is bigger than - * /proc/sys/kernel/rtsig-max / rtsig_overflow_threshold + * "/proc/sys/kernel/rtsig-max" / "rtsig_overflow_threshold" */ if (rtsig_max / rtscf->overflow_threshold < rtsig_nr) { ngx_log_debug2(NGX_LOG_DEBUG_EVENT, cycle->log, 0, "rtsig queue state: %d/%d", rtsig_nr, rtsig_max); - while (ngx_rtsig_process_events(cycle) == NGX_OK) { + while (ngx_rtsig_process_events(cycle, 0, flags) == NGX_OK) + { /* void */ } } @@ -734,20 +648,17 @@ * so drain the rt signal queue unconditionally */ - while (ngx_rtsig_process_events(cycle) == NGX_OK) { /* void */ } + while (ngx_rtsig_process_events(cycle, 0, flags) == NGX_OK) { + /* void */ + } } tested = 0; } } - if (ngx_posted_events) { - if (ngx_threaded) { - ngx_wakeup_worker_thread(cycle); - - } else { - ngx_event_process_posted(cycle); - } + if (flags & NGX_UPDATE_TIME) { + ngx_time_update(0, 0); } ngx_log_error(NGX_LOG_ALERT, cycle->log, 0,