nginx-0.0.3-2004-04-15-00:34:05 import

This commit is contained in:
Igor Sysoev 2004-04-14 20:34:05 +00:00
parent b3968b314f
commit cccc552894
13 changed files with 293 additions and 87 deletions

View File

@ -277,6 +277,13 @@ static ngx_int_t ngx_getopt(ngx_master_ctx_t *ctx, ngx_cycle_t *cycle)
switch (ctx->argv[i][1]) { switch (ctx->argv[i][1]) {
case 'c': case 'c':
if (ctx->argv[i + 1] == NULL) {
ngx_log_error(NGX_LOG_EMERG, cycle->log, 0,
"the option: \"%s\" requires file name",
ctx->argv[i]);
return NGX_ERROR;
}
cycle->conf_file.data = (u_char *) ctx->argv[++i]; cycle->conf_file.data = (u_char *) ctx->argv[++i];
cycle->conf_file.len = ngx_strlen(cycle->conf_file.data); cycle->conf_file.len = ngx_strlen(cycle->conf_file.data);
break; break;

View File

@ -101,11 +101,6 @@ typedef int ngx_flag_t;
#define ngx_inline inline #define ngx_inline inline
#endif #endif
#ifndef INFTIM /* Linux */
#define INFTIM -1
#endif
#ifndef INADDR_NONE /* Solaris */ #ifndef INADDR_NONE /* Solaris */
#define INADDR_NONE ((unsigned int) -1) #define INADDR_NONE ((unsigned int) -1)
#endif #endif

View File

@ -23,7 +23,7 @@ ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle)
{ {
void *rv; void *rv;
ngx_uint_t i, n, failed; ngx_uint_t i, n, failed;
ngx_log_t *log; ngx_log_t *log, *new_log;
ngx_conf_t conf; ngx_conf_t conf;
ngx_pool_t *pool; ngx_pool_t *pool;
ngx_cycle_t *cycle, **old; ngx_cycle_t *cycle, **old;
@ -44,6 +44,9 @@ ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle)
} }
cycle->pool = pool; cycle->pool = pool;
pool->log = log;
cycle->log = log;
cycle->old_cycle = old_cycle; cycle->old_cycle = old_cycle;
cycle->conf_file = old_cycle->conf_file; cycle->conf_file = old_cycle->conf_file;
@ -71,7 +74,7 @@ ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle)
cycle->open_files.pool = pool; cycle->open_files.pool = pool;
if (!(cycle->log = ngx_log_create_errlog(cycle, NULL))) { if (!(new_log = ngx_log_create_errlog(cycle, NULL))) {
ngx_destroy_pool(pool); ngx_destroy_pool(pool);
return NULL; return NULL;
} }
@ -129,12 +132,14 @@ ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle)
conf.module_type = NGX_CORE_MODULE; conf.module_type = NGX_CORE_MODULE;
conf.cmd_type = NGX_MAIN_CONF; conf.cmd_type = NGX_MAIN_CONF;
cycle->log = new_log;
if (ngx_conf_parse(&conf, &cycle->conf_file) != NGX_CONF_OK) { if (ngx_conf_parse(&conf, &cycle->conf_file) != NGX_CONF_OK) {
ngx_destroy_pool(pool); ngx_destroy_pool(pool);
return NULL; return NULL;
} }
cycle->log = log;
for (i = 0; ngx_modules[i]; i++) { for (i = 0; ngx_modules[i]; i++) {
if (ngx_modules[i]->type != NGX_CORE_MODULE) { if (ngx_modules[i]->type != NGX_CORE_MODULE) {
@ -203,6 +208,8 @@ ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle)
} }
} }
cycle->log = new_log;
pool->log = new_log;
if (!failed) { if (!failed) {
if (old_cycle->listening.nelts) { if (old_cycle->listening.nelts) {

View File

@ -236,6 +236,7 @@ static int ngx_devpoll_del_event(ngx_event_t *ev, int event, u_int flags)
} }
ev->active = 0; ev->active = 0;
ev->posted = 0;
if (flags & NGX_CLOSE_EVENT) { if (flags & NGX_CLOSE_EVENT) {
return NGX_OK; return NGX_OK;
@ -312,7 +313,7 @@ int ngx_devpoll_process_events(ngx_cycle_t *cycle)
{ {
int events; int events;
ngx_int_t i; ngx_int_t i;
ngx_uint_t j; ngx_uint_t j, lock, expire;
size_t n; size_t n;
ngx_msec_t timer; ngx_msec_t timer;
ngx_err_t err; ngx_err_t err;
@ -322,13 +323,43 @@ int ngx_devpoll_process_events(ngx_cycle_t *cycle)
struct dvpoll dvp; struct dvpoll dvp;
struct timeval tv; struct timeval tv;
timer = ngx_event_find_timer(); for ( ;; ) {
ngx_old_elapsed_msec = ngx_elapsed_msec; timer = ngx_event_find_timer();
if (timer == 0) { if (timer != 0) {
timer = (ngx_msec_t) INFTIM; break;
}
ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
"devpoll expired timer");
ngx_event_expire_timers(0);
} }
/* NGX_TIMER_INFINITE == INFTIM */
if (timer == NGX_TIMER_INFINITE) {
expire = 0;
} else {
expire = 1;
}
if (ngx_accept_mutex) {
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;
expire = 0;
}
}
ngx_old_elapsed_msec = ngx_elapsed_msec;
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0, ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
"devpoll timer: %d", timer); "devpoll timer: %d", timer);
@ -337,6 +368,7 @@ int ngx_devpoll_process_events(ngx_cycle_t *cycle)
if (write(dp, change_list, n) != (ssize_t) n) { if (write(dp, change_list, n) != (ssize_t) n) {
ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
"write(/dev/poll) failed"); "write(/dev/poll) failed");
ngx_accept_mutex_unlock();
return NGX_ERROR; return NGX_ERROR;
} }
} }
@ -363,10 +395,11 @@ int ngx_devpoll_process_events(ngx_cycle_t *cycle)
if (err) { if (err) {
ngx_log_error((err == NGX_EINTR) ? NGX_LOG_INFO : NGX_LOG_ALERT, ngx_log_error((err == NGX_EINTR) ? NGX_LOG_INFO : NGX_LOG_ALERT,
cycle->log, err, "ioctl(DP_POLL) failed"); cycle->log, err, "ioctl(DP_POLL) failed");
ngx_accept_mutex_unlock();
return NGX_ERROR; return NGX_ERROR;
} }
if (timer != (ngx_msec_t) INFTIM) { if (timer != NGX_TIMER_INFINITE) {
delta = ngx_elapsed_msec - delta; delta = ngx_elapsed_msec - delta;
ngx_log_debug2(NGX_LOG_DEBUG_EVENT, cycle->log, 0, ngx_log_debug2(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
@ -375,10 +408,18 @@ int ngx_devpoll_process_events(ngx_cycle_t *cycle)
if (events == 0) { if (events == 0) {
ngx_log_error(NGX_LOG_ALERT, cycle->log, 0, ngx_log_error(NGX_LOG_ALERT, cycle->log, 0,
"ioctl(DP_POLL) returned no events without timeout"); "ioctl(DP_POLL) returned no events without timeout");
ngx_accept_mutex_unlock();
return NGX_ERROR; return NGX_ERROR;
} }
} }
if (ngx_mutex_lock(ngx_posted_events_mutex) == NGX_ERROR) {
ngx_accept_mutex_unlock();
return NGX_ERROR;
}
lock = 1;
for (i = 0; i < events; i++) { for (i = 0; i < events; i++) {
c = &ngx_cycle->connections[event_list[i].fd]; c = &ngx_cycle->connections[event_list[i].fd];
@ -421,25 +462,68 @@ int ngx_devpoll_process_events(ngx_cycle_t *cycle)
event_list[i].events, event_list[i].revents); event_list[i].events, event_list[i].revents);
} }
if ((event_list[i].events & (POLLIN|POLLERR|POLLHUP))
&& c->read->active)
{
c->read->ready = 1;
c->read->event_handler(c->read);
}
if ((event_list[i].events & (POLLOUT|POLLERR|POLLHUP)) if ((event_list[i].events & (POLLOUT|POLLERR|POLLHUP))
&& c->write->active) && c->write->active)
{ {
c->write->ready = 1; c->write->ready = 1;
c->write->event_handler(c->write);
if (!ngx_threaded && !ngx_accept_mutex_held) {
c->write->event_handler(c->write);
} else {
ngx_post_event(c->write);
}
}
/*
* POLLIN must be handled after POLLOUT because we use
* the optimization to avoid the unnecessary mutex locking/unlocking
* if the accept event is the last one.
*/
if ((event_list[i].events & (POLLIN|POLLERR|POLLHUP))
&& c->read->active)
{
c->read->ready = 1;
if (!ngx_threaded && !ngx_accept_mutex_held) {
c->read->event_handler(c->read);
} else if (!c->read->accept) {
ngx_post_event(c->read);
} else {
ngx_mutex_unlock(ngx_posted_events_mutex);
c->read->event_handler(c->read);
if (i + 1 == events) {
lock = 0;
break;
}
if (ngx_mutex_lock(ngx_posted_events_mutex) == NGX_ERROR) {
ngx_accept_mutex_unlock();
return NGX_ERROR;
}
}
} }
} }
if (timer != (ngx_msec_t) INFTIM && delta) { if (lock) {
ngx_mutex_unlock(ngx_posted_events_mutex);
}
ngx_accept_mutex_unlock();
if (expire && delta) {
ngx_event_expire_timers((ngx_msec_t) delta); ngx_event_expire_timers((ngx_msec_t) delta);
} }
if (!ngx_threaded) {
ngx_event_process_posted(cycle);
}
return NGX_OK; return NGX_OK;
} }

View File

@ -353,28 +353,37 @@ int ngx_epoll_process_events(ngx_cycle_t *cycle)
ngx_connection_t *c; ngx_connection_t *c;
ngx_epoch_msec_t delta; ngx_epoch_msec_t delta;
timer = ngx_event_find_timer(); for ( ;; ) {
ngx_old_elapsed_msec = ngx_elapsed_msec; timer = ngx_event_find_timer();
if (timer == -1) { if (timer != 0) {
timer = 0; break;
expire = 1; }
} else if (timer == 0) { ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
timer = (ngx_msec_t) -1; "epoll expired timer");
ngx_event_expire_timers(0);
}
/* NGX_TIMER_INFINITE == INFTIM */
if (timer == NGX_TIMER_INFINITE) {
expire = 0; expire = 0;
} else { } else {
expire = 1; expire = 1;
} }
ngx_old_elapsed_msec = ngx_elapsed_msec;
if (ngx_accept_mutex) { if (ngx_accept_mutex) {
if (ngx_trylock_accept_mutex(cycle) == NGX_ERROR) { if (ngx_trylock_accept_mutex(cycle) == NGX_ERROR) {
return NGX_ERROR; return NGX_ERROR;
} }
if (ngx_accept_mutex_held == 0 if (ngx_accept_mutex_held == 0
&& (timer == -1 || timer > ngx_accept_mutex_delay)) && (timer == NGX_TIMER_INFINITE || timer > ngx_accept_mutex_delay))
{ {
timer = ngx_accept_mutex_delay; timer = ngx_accept_mutex_delay;
expire = 0; expire = 0;
@ -398,7 +407,7 @@ int ngx_epoll_process_events(ngx_cycle_t *cycle)
delta = ngx_elapsed_msec; delta = ngx_elapsed_msec;
ngx_elapsed_msec = tv.tv_sec * 1000 + tv.tv_usec / 1000 - ngx_start_msec; ngx_elapsed_msec = tv.tv_sec * 1000 + tv.tv_usec / 1000 - ngx_start_msec;
if (timer != (ngx_msec_t) -1) { if (timer != NGX_TIMER_INFINITE) {
delta = ngx_elapsed_msec - delta; delta = ngx_elapsed_msec - delta;
ngx_log_debug2(NGX_LOG_DEBUG_EVENT, cycle->log, 0, ngx_log_debug2(NGX_LOG_DEBUG_EVENT, cycle->log, 0,

View File

@ -353,20 +353,34 @@ static ngx_int_t ngx_kqueue_process_events(ngx_cycle_t *cycle)
struct timeval tv; struct timeval tv;
struct timespec ts, *tp; struct timespec ts, *tp;
timer = ngx_event_find_timer(); for ( ;; ) {
timer = ngx_event_find_timer();
#if (NGX_THREADS) #if (NGX_THREADS)
if (timer == NGX_TIMER_ERROR) { if (timer == NGX_TIMER_ERROR) {
return NGX_ERROR; return NGX_ERROR;
} }
/* /*
* TODO: if timer is 0 and any worker thread is still busy * TODO: if timer is NGX_TIMER_INFINITE and any worker thread
* then set 500 ms timeout * is still busy then set the configurable 500ms timeout
*/ * to wake up another worker thread
*/
#endif #endif
if (timer != 0) {
break;
}
ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
"kevent expired timer");
ngx_event_expire_timers(0);
/* TODO: if ngx_threaded then wake up the worker thread */
}
ngx_old_elapsed_msec = ngx_elapsed_msec; ngx_old_elapsed_msec = ngx_elapsed_msec;
expire = 1; expire = 1;
@ -376,26 +390,21 @@ static ngx_int_t ngx_kqueue_process_events(ngx_cycle_t *cycle)
} }
if (ngx_accept_mutex_held == 0 if (ngx_accept_mutex_held == 0
&& (timer == 0 || timer > ngx_accept_mutex_delay)) && (timer == NGX_TIMER_INFINITE || timer > ngx_accept_mutex_delay))
{ {
timer = ngx_accept_mutex_delay; timer = ngx_accept_mutex_delay;
expire = 0; expire = 0;
} }
} }
if (timer == -1) { if (timer == NGX_TIMER_INFINITE) {
ts.tv_sec = 0; tp = NULL;
ts.tv_nsec = 0; expire = 0;
tp = &ts;
} else if (timer) { } else {
ts.tv_sec = timer / 1000; ts.tv_sec = timer / 1000;
ts.tv_nsec = (timer % 1000) * 1000000; ts.tv_nsec = (timer % 1000) * 1000000;
tp = &ts; tp = &ts;
} else {
tp = NULL;
expire = 0;
} }
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0, ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
@ -427,7 +436,7 @@ static ngx_int_t ngx_kqueue_process_events(ngx_cycle_t *cycle)
return NGX_ERROR; return NGX_ERROR;
} }
if (timer) { if (timer != NGX_TIMER_INFINITE) {
delta = ngx_elapsed_msec - delta; delta = ngx_elapsed_msec - delta;
ngx_log_debug2(NGX_LOG_DEBUG_EVENT, cycle->log, 0, ngx_log_debug2(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
@ -550,6 +559,8 @@ static ngx_int_t ngx_kqueue_process_events(ngx_cycle_t *cycle)
ngx_accept_mutex_unlock(); ngx_accept_mutex_unlock();
/* TODO: wake up worker thread */
if (expire && delta) { if (expire && delta) {
ngx_event_expire_timers((ngx_msec_t) delta); ngx_event_expire_timers((ngx_msec_t) delta);
} }

View File

@ -277,14 +277,22 @@ int ngx_poll_process_events(ngx_cycle_t *cycle)
expire = 0; expire = 0;
} else { } else {
timer = ngx_event_find_timer(); for ( ;; ) {
timer = ngx_event_find_timer();
if (timer == -1) { if (timer != 0) {
timer = 0; break;
expire = 1; }
} else if (timer == 0) { ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
timer = (ngx_msec_t) INFTIM; "poll expired timer");
ngx_event_expire_timers(0);
}
/* NGX_TIMER_INFINITE == INFTIM */
if (timer == NGX_TIMER_INFINITE) {
expire = 0; expire = 0;
} else { } else {
@ -308,7 +316,7 @@ int ngx_poll_process_events(ngx_cycle_t *cycle)
} }
if (ngx_accept_mutex_held == 0 if (ngx_accept_mutex_held == 0
&& (timer == (ngx_msec_t) INFTIM || timer > ngx_accept_mutex_delay)) && (timer == NGX_TIMER_INFINITE || timer > ngx_accept_mutex_delay))
{ {
timer = ngx_accept_mutex_delay; timer = ngx_accept_mutex_delay;
expire = 0; expire = 0;
@ -341,7 +349,7 @@ int ngx_poll_process_events(ngx_cycle_t *cycle)
return NGX_ERROR; return NGX_ERROR;
} }
if (timer != (ngx_msec_t) INFTIM) { if (timer != NGX_TIMER_INFINITE) {
delta = ngx_elapsed_msec - delta; delta = ngx_elapsed_msec - delta;
ngx_log_debug2(NGX_LOG_DEBUG_EVENT, cycle->log, 0, ngx_log_debug2(NGX_LOG_DEBUG_EVENT, cycle->log, 0,

View File

@ -192,6 +192,7 @@ int ngx_rtsig_process_events(ngx_cycle_t *cycle)
{ {
int signo; int signo;
ngx_int_t instance, i; ngx_int_t instance, i;
ngx_uint_t expire;
size_t n; size_t n;
ngx_msec_t timer; ngx_msec_t timer;
ngx_err_t err; ngx_err_t err;
@ -199,22 +200,50 @@ int ngx_rtsig_process_events(ngx_cycle_t *cycle)
struct timeval tv; struct timeval tv;
struct timespec ts, *tp; struct timespec ts, *tp;
struct sigaction sa; struct sigaction sa;
ngx_connection_t *c;
ngx_epoch_msec_t delta; ngx_epoch_msec_t delta;
ngx_connection_t *c;
ngx_rtsig_conf_t *rtscf; ngx_rtsig_conf_t *rtscf;
timer = ngx_event_find_timer(); for ( ;; ) {
ngx_old_elapsed_msec = ngx_elapsed_msec; timer = ngx_event_find_timer();
if (timer) { if (timer != 0) {
break;
}
ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
"rtsig expired timer");
ngx_event_expire_timers(0);
}
expire = 1;
if (ngx_accept_mutex) {
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;
expire = 0;
}
}
if (timer == NGX_TIMER_INFINITE) {
tp = NULL;
expire = 0;
} else {
ts.tv_sec = timer / 1000; ts.tv_sec = timer / 1000;
ts.tv_nsec = (timer % 1000) * 1000000; ts.tv_nsec = (timer % 1000) * 1000000;
tp = &ts; tp = &ts;
} else {
tp = NULL;
} }
ngx_old_elapsed_msec = ngx_elapsed_msec;
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0, ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
"rtsig timer: %d", timer); "rtsig timer: %d", timer);
@ -237,10 +266,11 @@ int ngx_rtsig_process_events(ngx_cycle_t *cycle)
if (err) { if (err) {
ngx_log_error((err == NGX_EINTR) ? NGX_LOG_INFO : NGX_LOG_ALERT, ngx_log_error((err == NGX_EINTR) ? NGX_LOG_INFO : NGX_LOG_ALERT,
cycle->log, err, "sigtimedwait() failed"); cycle->log, err, "sigtimedwait() failed");
ngx_accept_mutex_unlock();
return NGX_ERROR; return NGX_ERROR;
} }
if (timer) { if (timer != NGX_TIMER_INFINITE) {
delta = ngx_elapsed_msec - delta; delta = ngx_elapsed_msec - delta;
ngx_log_debug2(NGX_LOG_DEBUG_EVENT, cycle->log, 0, ngx_log_debug2(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
@ -263,18 +293,50 @@ int ngx_rtsig_process_events(ngx_cycle_t *cycle)
if (si.si_band & (POLLIN|POLLHUP|POLLERR)) { if (si.si_band & (POLLIN|POLLHUP|POLLERR)) {
if (c->read->active) { if (c->read->active) {
c->read->ready = 1; c->read->ready = 1;
c->read->event_handler(c->read);
if (!ngx_threaded && !ngx_accept_mutex_held) {
c->read->event_handler(c->read);
} else if (c->read->accept) {
c->read->event_handler(c->read);
} else {
if (ngx_mutex_lock(ngx_posted_events_mutex) == NGX_ERROR) {
ngx_accept_mutex_unlock();
return NGX_ERROR;
}
ngx_post_event(c->read);
ngx_mutex_unlock(ngx_posted_events_mutex);
}
} }
} }
if (si.si_band & (POLLOUT|POLLHUP|POLLERR)) { if (si.si_band & (POLLOUT|POLLHUP|POLLERR)) {
if (c->write->active) { if (c->write->active) {
c->write->ready = 1; c->write->ready = 1;
c->write->event_handler(c->write);
if (!ngx_threaded && !ngx_accept_mutex_held) {
c->write->event_handler(c->write);
} else {
if (ngx_mutex_lock(ngx_posted_events_mutex) == NGX_ERROR) {
ngx_accept_mutex_unlock();
return NGX_ERROR;
}
ngx_post_event(c->write);
ngx_mutex_unlock(ngx_posted_events_mutex);
}
} }
} }
} else if (signo == SIGIO) { } else if (signo == SIGIO) {
ngx_accept_mutex_unlock();
ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
"signal queue overflowed: " "signal queue overflowed: "
"SIGIO, fd:%d, band:%X", si.si_fd, si.si_band); "SIGIO, fd:%d, band:%X", si.si_fd, si.si_band);
@ -300,13 +362,21 @@ int ngx_rtsig_process_events(ngx_cycle_t *cycle)
} else { } else {
ngx_log_error(NGX_LOG_ALERT, cycle->log, 0, ngx_log_error(NGX_LOG_ALERT, cycle->log, 0,
"sigtimedwait() returned unexpected signal: %d", signo); "sigtimedwait() returned unexpected signal: %d", signo);
ngx_accept_mutex_unlock();
return NGX_ERROR; return NGX_ERROR;
} }
if (timer != (ngx_msec_t) -1 && delta) {
ngx_accept_mutex_unlock();
if (expire && delta) {
ngx_event_expire_timers((ngx_msec_t) delta); ngx_event_expire_timers((ngx_msec_t) delta);
} }
if (!ngx_threaded) {
ngx_event_process_posted(cycle);
}
return NGX_OK; return NGX_OK;
} }

View File

@ -263,7 +263,19 @@ static int ngx_select_process_events(ngx_cycle_t *cycle)
static ngx_epoch_msec_t deltas = 0; static ngx_epoch_msec_t deltas = 0;
#endif #endif
timer = ngx_event_find_timer(); for ( ;; ) {
timer = ngx_event_find_timer();
if (timer != 0) {
break;
}
ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
"select expired timer");
ngx_event_expire_timers(0);
}
ngx_old_elapsed_msec = ngx_elapsed_msec; ngx_old_elapsed_msec = ngx_elapsed_msec;
expire = 1; expire = 1;
@ -276,7 +288,7 @@ static int ngx_select_process_events(ngx_cycle_t *cycle)
} }
if (ngx_accept_mutex_held == 0 if (ngx_accept_mutex_held == 0
&& (timer == 0 || timer > ngx_accept_mutex_delay)) && (timer == NGX_TIMER_INFINITE || timer > ngx_accept_mutex_delay))
{ {
timer = ngx_accept_mutex_delay; timer = ngx_accept_mutex_delay;
expire = 0; expire = 0;
@ -306,19 +318,14 @@ static int ngx_select_process_events(ngx_cycle_t *cycle)
} }
#endif #endif
if (timer == -1) { if (timer == NGX_TIMER_INFINITE) {
tv.tv_sec = 0; tp = NULL;
tv.tv_usec = 0; expire = 0;
tp = &tv;
} else if (timer) { } else {
tv.tv_sec = timer / 1000; tv.tv_sec = timer / 1000;
tv.tv_usec = (timer % 1000) * 1000; tv.tv_usec = (timer % 1000) * 1000;
tp = &tv; tp = &tv;
} else {
tp = NULL;
expire = 0;
} }
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0, ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
@ -344,7 +351,7 @@ static int ngx_select_process_events(ngx_cycle_t *cycle)
#if (HAVE_SELECT_CHANGE_TIMEOUT) #if (HAVE_SELECT_CHANGE_TIMEOUT)
if (timer) { if (timer != NGX_TIMER_INFINITE) {
delta = timer - (tv.tv_sec * 1000 + tv.tv_usec / 1000); delta = timer - (tv.tv_sec * 1000 + tv.tv_usec / 1000);
/* /*
@ -383,7 +390,7 @@ static int ngx_select_process_events(ngx_cycle_t *cycle)
delta = ngx_elapsed_msec; delta = ngx_elapsed_msec;
ngx_elapsed_msec = tv.tv_sec * 1000 + tv.tv_usec / 1000 - ngx_start_msec; ngx_elapsed_msec = tv.tv_sec * 1000 + tv.tv_usec / 1000 - ngx_start_msec;
if (timer) { if (timer != NGX_TIMER_INFINITE) {
delta = ngx_elapsed_msec - delta; delta = ngx_elapsed_msec - delta;
ngx_log_debug2(NGX_LOG_DEBUG_EVENT, cycle->log, 0, ngx_log_debug2(NGX_LOG_DEBUG_EVENT, cycle->log, 0,

View File

@ -40,7 +40,7 @@ ngx_msec_t ngx_event_find_timer(void)
ngx_rbtree_t *node; ngx_rbtree_t *node;
if (ngx_event_timer_rbtree == &ngx_event_timer_sentinel) { if (ngx_event_timer_rbtree == &ngx_event_timer_sentinel) {
return 0; return NGX_TIMER_INFINITE;
} }
if (ngx_mutex_lock(ngx_event_timer_mutex) == NGX_ERROR) { if (ngx_mutex_lock(ngx_event_timer_mutex) == NGX_ERROR) {
@ -59,7 +59,7 @@ ngx_msec_t ngx_event_find_timer(void)
(node->key * NGX_TIMER_RESOLUTION - ngx_elapsed_msec); (node->key * NGX_TIMER_RESOLUTION - ngx_elapsed_msec);
#endif #endif
return timer > 0 ? timer: -1 ; return timer > 0 ? timer: 0 ;
} }
@ -83,7 +83,7 @@ void ngx_event_expire_timers(ngx_msec_t timer)
ngx_mutex_unlock(ngx_event_timer_mutex); ngx_mutex_unlock(ngx_event_timer_mutex);
if ((ngx_msec_t) node->key <= (ngx_msec_t) if (node->key <= (ngx_msec_t)
(ngx_old_elapsed_msec + timer) / NGX_TIMER_RESOLUTION) (ngx_old_elapsed_msec + timer) / NGX_TIMER_RESOLUTION)
{ {
ev = (ngx_event_t *) ev = (ngx_event_t *)

View File

@ -7,7 +7,8 @@
#include <ngx_event.h> #include <ngx_event.h>
#define NGX_TIMER_ERROR (ngx_msec_t) -1 #define NGX_TIMER_INFINITE -1
#define NGX_TIMER_ERROR -2
/* /*
* 32 bit timer key value resolution * 32 bit timer key value resolution

View File

@ -93,4 +93,8 @@ extern ssize_t sendfile(int s, int fd, int32_t *offset, size_t size);
#define ngx_setproctitle(title) #define ngx_setproctitle(title)
/* STUB */
#define HAVE_LITTLE_ENDIAN 1
#endif /* _NGX_LINUX_CONFIG_H_INCLUDED_ */ #endif /* _NGX_LINUX_CONFIG_H_INCLUDED_ */

View File

@ -26,7 +26,6 @@
#include <sys/socket.h> #include <sys/socket.h>
#include <sys/sendfile.h> #include <sys/sendfile.h>
#include <sys/filio.h> /* FIONBIO */ #include <sys/filio.h> /* FIONBIO */
#include <sys/stropts.h> /* INFTIM */
#include <sys/systeminfo.h> #include <sys/systeminfo.h>
#include <netinet/in.h> #include <netinet/in.h>
#include <arpa/inet.h> #include <arpa/inet.h>
@ -75,4 +74,8 @@
#define ngx_setproctitle(title) #define ngx_setproctitle(title)
/* STUB */
#define HAVE_LITTLE_ENDIAN 1
#endif /* _NGX_SOLARIS_CONFIG_H_INCLUDED_ */ #endif /* _NGX_SOLARIS_CONFIG_H_INCLUDED_ */