# HG changeset patch # User Igor Sysoev # Date 1080918800 0 # Node ID 4b1a3a4acc60fbf8a7e9fdb985fb4eb523f658c9 # Parent bcbe876f42622c124fade3ecb39ec1a1c70f08d3 nginx-0.0.3-2004-04-02-19:13:20 import diff --git a/src/event/modules/ngx_aio_module.c b/src/event/modules/ngx_aio_module.c --- a/src/event/modules/ngx_aio_module.c +++ b/src/event/modules/ngx_aio_module.c @@ -14,7 +14,7 @@ static void ngx_aio_done(ngx_cycle_t *cy static int ngx_aio_add_event(ngx_event_t *ev, int event, u_int flags); static int ngx_aio_del_event(ngx_event_t *ev, int event, u_int flags); static int ngx_aio_del_connection(ngx_connection_t *c, u_int flags); -static int ngx_aio_process_events(ngx_log_t *log); +static int ngx_aio_process_events(ngx_cycle_t *cycle); ngx_os_io_t ngx_os_aio = { @@ -53,7 +53,7 @@ ngx_module_t ngx_aio_module = { NULL, /* module directives */ NGX_EVENT_MODULE, /* module type */ NULL, /* init module */ - NULL /* init child */ + NULL /* init process */ }; @@ -137,9 +137,9 @@ static int ngx_aio_del_connection(ngx_co } -static int ngx_aio_process_events(ngx_log_t *log) +static int ngx_aio_process_events(ngx_cycle_t *cycle) { - return ngx_kqueue_module_ctx.actions.process(log); + return ngx_kqueue_module_ctx.actions.process(cycle); } #endif /* HAVE_KQUEUE */ diff --git a/src/event/modules/ngx_devpoll_module.c b/src/event/modules/ngx_devpoll_module.c --- a/src/event/modules/ngx_devpoll_module.c +++ b/src/event/modules/ngx_devpoll_module.c @@ -36,7 +36,7 @@ static void ngx_devpoll_done(ngx_cycle_t static int ngx_devpoll_add_event(ngx_event_t *ev, int event, u_int flags); static int ngx_devpoll_del_event(ngx_event_t *ev, int event, u_int flags); static int ngx_devpoll_set_event(ngx_event_t *ev, int event, u_int flags); -static int ngx_devpoll_process_events(ngx_log_t *log); +static int ngx_devpoll_process_events(ngx_cycle_t *cycle); static void *ngx_devpoll_create_conf(ngx_cycle_t *cycle); static char *ngx_devpoll_init_conf(ngx_cycle_t *cycle, void *conf); @@ -308,13 +308,15 @@ static int ngx_devpoll_set_event(ngx_eve } -int ngx_devpoll_process_events(ngx_log_t *log) +int ngx_devpoll_process_events(ngx_cycle_t *cycle) { - int events, i, j; + int events; + ngx_int_t i; + ngx_uint_t j; size_t n; ngx_msec_t timer; ngx_err_t err; - ngx_cycle_t **cycle; + ngx_cycle_t **old_cycle; ngx_connection_t *c; ngx_epoch_msec_t delta; struct dvpoll dvp; @@ -327,12 +329,13 @@ int ngx_devpoll_process_events(ngx_log_t timer = (ngx_msec_t) INFTIM; } - ngx_log_debug1(NGX_LOG_DEBUG_EVENT, log, 0, "devpoll timer: %d", timer); + ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0, + "devpoll timer: %d", timer); if (nchanges) { n = nchanges * sizeof(struct pollfd); if (write(dp, change_list, n) != (ssize_t) n) { - ngx_log_error(NGX_LOG_ALERT, log, ngx_errno, + ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, "write(/dev/poll) failed"); return NGX_ERROR; } @@ -359,18 +362,18 @@ int ngx_devpoll_process_events(ngx_log_t if (err) { ngx_log_error((err == NGX_EINTR) ? NGX_LOG_INFO : NGX_LOG_ALERT, - log, err, "ioctl(DP_POLL) failed"); + cycle->log, err, "ioctl(DP_POLL) failed"); return NGX_ERROR; } if (timer != (ngx_msec_t) INFTIM) { delta = ngx_elapsed_msec - delta; - ngx_log_debug2(NGX_LOG_DEBUG_EVENT, log, 0, + ngx_log_debug2(NGX_LOG_DEBUG_EVENT, cycle->log, 0, "devpoll timer: %d, delta: %d", timer, (int) delta); } else { if (events == 0) { - ngx_log_error(NGX_LOG_ALERT, log, 0, + ngx_log_error(NGX_LOG_ALERT, cycle->log, 0, "ioctl(DP_POLL) returned no events without timeout"); return NGX_ERROR; } @@ -380,12 +383,12 @@ int ngx_devpoll_process_events(ngx_log_t c = &ngx_cycle->connections[event_list[i].fd]; if (c->fd == -1) { - cycle = ngx_old_cycles.elts; + old_cycle = ngx_old_cycles.elts; for (j = 0; j < ngx_old_cycles.nelts; j++) { - if (cycle[i] == NULL) { + if (old_cycle[j] == NULL) { continue; } - c = &cycle[j]->connections[event_list[i].fd]; + c = &old_cycle[j]->connections[event_list[i].fd]; if (c->fd != -1) { break; } @@ -393,17 +396,17 @@ int ngx_devpoll_process_events(ngx_log_t } if (c->fd == -1) { - ngx_log_error(NGX_LOG_EMERG, log, 0, "unknown cycle"); + ngx_log_error(NGX_LOG_EMERG, cycle->log, 0, "unknown cycle"); exit(1); } - ngx_log_debug3(NGX_LOG_DEBUG_EVENT, log, 0, + ngx_log_debug3(NGX_LOG_DEBUG_EVENT, cycle->log, 0, "devpoll: fd:%d, ev:%04X, rev:%04X", event_list[i].fd, event_list[i].events, event_list[i].revents); if (event_list[i].revents & (POLLERR|POLLHUP|POLLNVAL)) { - ngx_log_error(NGX_LOG_ALERT, log, 0, + ngx_log_error(NGX_LOG_ALERT, cycle->log, 0, "ioctl(DP_POLL) error fd:%d ev:%04X rev:%04X", event_list[i].fd, event_list[i].events, event_list[i].revents); @@ -411,7 +414,7 @@ int ngx_devpoll_process_events(ngx_log_t if (event_list[i].revents & ~(POLLIN|POLLOUT|POLLERR|POLLHUP|POLLNVAL)) { - ngx_log_error(NGX_LOG_ALERT, log, 0, + ngx_log_error(NGX_LOG_ALERT, cycle->log, 0, "strange ioctl(DP_POLL) events " "fd:%d ev:%04X rev:%04X", event_list[i].fd, diff --git a/src/event/modules/ngx_epoll_module.c b/src/event/modules/ngx_epoll_module.c --- a/src/event/modules/ngx_epoll_module.c +++ b/src/event/modules/ngx_epoll_module.c @@ -76,7 +76,7 @@ static int ngx_epoll_add_event(ngx_event static int ngx_epoll_del_event(ngx_event_t *ev, int event, u_int flags); static int ngx_epoll_add_connection(ngx_connection_t *c); static int ngx_epoll_del_connection(ngx_connection_t *c); -static int ngx_epoll_process_events(ngx_log_t *log); +static int ngx_epoll_process_events(ngx_cycle_t *cycle); static void *ngx_epoll_create_conf(ngx_cycle_t *cycle); static char *ngx_epoll_init_conf(ngx_cycle_t *cycle, void *conf); @@ -337,14 +337,13 @@ static int ngx_epoll_del_connection(ngx_ #endif -int ngx_epoll_process_events(ngx_log_t *log) +int ngx_epoll_process_events(ngx_cycle_t *cycle) { int events; ngx_int_t instance, i; size_t n; ngx_msec_t timer; ngx_err_t err; - ngx_cycle_t **cycle; struct timeval tv; ngx_connection_t *c; ngx_epoch_msec_t delta; @@ -357,7 +356,8 @@ int ngx_epoll_process_events(ngx_log_t * timer = (ngx_msec_t) -1; } - ngx_log_debug1(NGX_LOG_DEBUG_EVENT, log, 0, "epoll timer: %d", timer); + ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0, + "epoll timer: %d", timer); events = epoll_wait(ep, event_list, nevents, timer); @@ -376,11 +376,11 @@ int ngx_epoll_process_events(ngx_log_t * if (timer != (ngx_msec_t) -1) { delta = ngx_elapsed_msec - delta; - ngx_log_debug2(NGX_LOG_DEBUG_EVENT, log, 0, + ngx_log_debug2(NGX_LOG_DEBUG_EVENT, cycle->log, 0, "epoll timer: %d, delta: %d", timer, (int) delta); } else { if (events == 0) { - ngx_log_error(NGX_LOG_ALERT, log, 0, + ngx_log_error(NGX_LOG_ALERT, cycle->log, 0, "epoll_wait() returned no events without timeout"); return NGX_ERROR; } @@ -388,7 +388,7 @@ int ngx_epoll_process_events(ngx_log_t * if (err) { ngx_log_error((err == NGX_EINTR) ? NGX_LOG_INFO : NGX_LOG_ALERT, - log, err, "epoll_wait() failed"); + cycle->log, err, "epoll_wait() failed"); return NGX_ERROR; } @@ -398,7 +398,15 @@ int ngx_epoll_process_events(ngx_log_t * instance = (uintptr_t) c & 1; c = (ngx_connection_t *) ((uintptr_t) c & (uintptr_t) ~1); - ngx_log_debug3(NGX_LOG_DEBUG_EVENT, log, 0, + if (event_list[i].events & EPOLLIN) { + c->read->returned_instance = instance; + } + + if (event_list[i].events & EPOLLOUT) { + c->write->returned_instance = instance; + } + + ngx_log_debug3(NGX_LOG_DEBUG_EVENT, cycle->log, 0, "epoll: fd:%d ev:%04X d:" PTR_FMT, c->fd, event_list[i].events, event_list[i].data); @@ -409,19 +417,19 @@ int ngx_epoll_process_events(ngx_log_t * * that was just closed in this iteration */ - ngx_log_debug1(NGX_LOG_DEBUG_EVENT, log, 0, + ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0, "epoll: stale event " PTR_FMT, c); continue; } if (event_list[i].events & (EPOLLERR|EPOLLHUP)) { - ngx_log_debug2(NGX_LOG_DEBUG_EVENT, log, 0, + ngx_log_debug2(NGX_LOG_DEBUG_EVENT, cycle->log, 0, "epoll_wait() error on fd:%d ev:%04X", c->fd, event_list[i].events); } if (event_list[i].events & ~(EPOLLIN|EPOLLOUT|EPOLLERR|EPOLLHUP)) { - ngx_log_error(NGX_LOG_ALERT, log, 0, + ngx_log_error(NGX_LOG_ALERT, cycle->log, 0, "strange epoll_wait() events fd:%d ev:%04X", c->fd, event_list[i].events); } diff --git a/src/event/modules/ngx_kqueue_module.c b/src/event/modules/ngx_kqueue_module.c --- a/src/event/modules/ngx_kqueue_module.c +++ b/src/event/modules/ngx_kqueue_module.c @@ -346,7 +346,8 @@ static int ngx_kqueue_set_event(ngx_even static ngx_int_t ngx_kqueue_process_events(ngx_cycle_t *cycle) { int events; - ngx_int_t i, instance; + ngx_int_t i; + ngx_uint_t instance; ngx_err_t err; ngx_msec_t timer; ngx_event_t *ev; @@ -517,10 +518,7 @@ static ngx_int_t ngx_kqueue_process_even } -#if 0 - if (ngx_threaded || ngx_accept_token) { -#endif - if (ngx_accept_mutex_held) { + if (ngx_threaded || ngx_accept_mutex_held) { if (ev->accept) { ngx_mutex_unlock(ngx_posted_events_mutex); @@ -533,7 +531,7 @@ static ngx_int_t ngx_kqueue_process_even } } else { - ev->next = ngx_posted_events; + ev->next = (ngx_event_t *) ngx_posted_events; ngx_posted_events = ev; } @@ -551,11 +549,9 @@ static ngx_int_t ngx_kqueue_process_even ngx_event_expire_timers((ngx_msec_t) delta); } -#if (NGX_THREADS) if (ngx_threaded) { return NGX_OK; } -#endif for ( ;; ) { @@ -598,11 +594,6 @@ static ngx_int_t ngx_kqueue_process_even static void ngx_kqueue_thread_handler(ngx_event_t *ev) { - ngx_int_t instance; - - instance = (uintptr_t) ev & 1; - ev = (ngx_event_t *) ((uintptr_t) ev & (uintptr_t) ~1); - if ((!ev->posted && !ev->active) || ev->instance != ev->returned_instance) { diff --git a/src/event/modules/ngx_poll_module.c b/src/event/modules/ngx_poll_module.c --- a/src/event/modules/ngx_poll_module.c +++ b/src/event/modules/ngx_poll_module.c @@ -13,7 +13,7 @@ static int ngx_poll_init(ngx_cycle_t *cy static void ngx_poll_done(ngx_cycle_t *cycle); static int ngx_poll_add_event(ngx_event_t *ev, int event, u_int flags); static int ngx_poll_del_event(ngx_event_t *ev, int event, u_int flags); -int ngx_poll_process_events(ngx_log_t *log); +int ngx_poll_process_events(ngx_cycle_t *cycle); static struct pollfd *event_list; @@ -49,7 +49,7 @@ ngx_module_t ngx_poll_module = { NULL, /* module directives */ NGX_EVENT_MODULE, /* module type */ NULL, /* init module */ - NULL /* init child */ + NULL /* init process */ }; @@ -161,7 +161,7 @@ static int ngx_poll_add_event(ngx_event_ static int ngx_poll_del_event(ngx_event_t *ev, int event, u_int flags) { - ngx_int_t i; + ngx_uint_t i; ngx_cycle_t **cycle; ngx_event_t *e; ngx_connection_t *c; @@ -245,13 +245,14 @@ static int ngx_poll_del_event(ngx_event_ } -int ngx_poll_process_events(ngx_log_t *log) +int ngx_poll_process_events(ngx_cycle_t *cycle) { int ready; - ngx_int_t i, j, nready, found; + ngx_int_t i, nready; + ngx_uint_t n, found; ngx_msec_t timer; ngx_err_t err; - ngx_cycle_t **cycle; + ngx_cycle_t **old_cycle; ngx_event_t *ev; ngx_epoch_msec_t delta; ngx_connection_t *c; @@ -272,11 +273,12 @@ int ngx_poll_process_events(ngx_log_t *l #if (NGX_DEBUG0) for (i = 0; i < nevents; i++) { - ngx_log_debug3(NGX_LOG_DEBUG_EVENT, log, 0, "poll: %d: fd:%d ev:%04X", + ngx_log_debug3(NGX_LOG_DEBUG_EVENT, cycle->log, 0, + "poll: %d: fd:%d ev:%04X", i, event_list[i].fd, event_list[i].events); } - ngx_log_debug1(NGX_LOG_DEBUG_EVENT, log, 0, "poll timer: %d", timer); + ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0, "poll timer: %d", timer); #endif ready = poll(event_list, (u_int) nevents, (int) timer); @@ -293,23 +295,23 @@ int ngx_poll_process_events(ngx_log_t *l delta = ngx_elapsed_msec; ngx_elapsed_msec = tv.tv_sec * 1000 + tv.tv_usec / 1000 - ngx_start_msec; - ngx_log_debug2(NGX_LOG_DEBUG_EVENT, log, 0, + ngx_log_debug2(NGX_LOG_DEBUG_EVENT, cycle->log, 0, "poll ready %d of %d", ready, nevents); if (err) { ngx_log_error((err == NGX_EINTR) ? NGX_LOG_INFO : NGX_LOG_ALERT, - log, err, "poll() failed"); + cycle->log, err, "poll() failed"); return NGX_ERROR; } if (timer != (ngx_msec_t) INFTIM) { delta = ngx_elapsed_msec - delta; - ngx_log_debug2(NGX_LOG_DEBUG_EVENT, log, 0, + ngx_log_debug2(NGX_LOG_DEBUG_EVENT, cycle->log, 0, "poll timer: %d, delta: %d", timer, (int) delta); } else { if (ready == 0) { - ngx_log_error(NGX_LOG_ALERT, log, 0, + ngx_log_error(NGX_LOG_ALERT, cycle->log, 0, "poll() returned no events without timeout"); return NGX_ERROR; } @@ -325,13 +327,13 @@ int ngx_poll_process_events(ngx_log_t *l for (i = 0; i < nevents && ready; i++) { #if 0 - ngx_log_debug4(NGX_LOG_DEBUG_EVENT, log, 0, + ngx_log_debug4(NGX_LOG_DEBUG_EVENT, cycle->log, 0, "poll: %d: fd:%d ev:%04X rev:%04X", i, event_list[i].fd, event_list[i].events, event_list[i].revents); #else if (event_list[i].revents) { - ngx_log_debug4(NGX_LOG_DEBUG_EVENT, log, 0, + ngx_log_debug4(NGX_LOG_DEBUG_EVENT, cycle->log, 0, "poll: %d: fd:%d ev:%04X rev:%04X", i, event_list[i].fd, event_list[i].events, event_list[i].revents); @@ -339,7 +341,7 @@ int ngx_poll_process_events(ngx_log_t *l #endif if (event_list[i].revents & (POLLERR|POLLHUP|POLLNVAL)) { - ngx_log_error(NGX_LOG_ALERT, log, 0, + ngx_log_error(NGX_LOG_ALERT, cycle->log, 0, "poll() error fd:%d ev:%04X rev:%04X", event_list[i].fd, event_list[i].events, event_list[i].revents); @@ -347,7 +349,7 @@ int ngx_poll_process_events(ngx_log_t *l if (event_list[i].revents & ~(POLLIN|POLLOUT|POLLERR|POLLHUP|POLLNVAL)) { - ngx_log_error(NGX_LOG_ALERT, log, 0, + ngx_log_error(NGX_LOG_ALERT, cycle->log, 0, "strange poll() events fd:%d ev:%04X rev:%04X", event_list[i].fd, event_list[i].events, event_list[i].revents); @@ -363,12 +365,12 @@ int ngx_poll_process_events(ngx_log_t *l c = &ngx_cycle->connections[event_list[i].fd]; if (c->fd == -1) { - cycle = ngx_old_cycles.elts; - for (j = 0; j < ngx_old_cycles.nelts; j++) { - if (cycle[j] == NULL) { + old_cycle = ngx_old_cycles.elts; + for (n = 0; n < ngx_old_cycles.nelts; n++) { + if (old_cycle[n] == NULL) { continue; } - c = &cycle[j]->connections[event_list[i].fd]; + c = &old_cycle[n]->connections[event_list[i].fd]; if (c->fd != -1) { break; } @@ -376,7 +378,7 @@ int ngx_poll_process_events(ngx_log_t *l } if (c->fd == -1) { - ngx_log_error(NGX_LOG_ALERT, log, 0, "unexpected event"); + ngx_log_error(NGX_LOG_ALERT, cycle->log, 0, "unexpected event"); /* * it is certainly our fault and it should be investigated, @@ -435,7 +437,7 @@ int ngx_poll_process_events(ngx_log_t *l } if (ready != 0) { - ngx_log_error(NGX_LOG_ALERT, log, 0, "poll ready != events"); + ngx_log_error(NGX_LOG_ALERT, cycle->log, 0, "poll ready != events"); } if (timer != (ngx_msec_t) INFTIM && delta) { diff --git a/src/event/modules/ngx_rtsig_module.c b/src/event/modules/ngx_rtsig_module.c --- a/src/event/modules/ngx_rtsig_module.c +++ b/src/event/modules/ngx_rtsig_module.c @@ -39,8 +39,8 @@ static int ngx_rtsig_init(ngx_cycle_t *c static void ngx_rtsig_done(ngx_cycle_t *cycle); static int ngx_rtsig_add_connection(ngx_connection_t *c); static int ngx_rtsig_del_connection(ngx_connection_t *c, u_int flags); -static int ngx_rtsig_process_events(ngx_log_t *log); -static int ngx_rtsig_process_overflow(ngx_log_t *log); +static int ngx_rtsig_process_events(ngx_cycle_t *cycle); +static int ngx_rtsig_process_overflow(ngx_cycle_t *cycle); static void *ngx_rtsig_create_conf(ngx_cycle_t *cycle); static char *ngx_rtsig_init_conf(ngx_cycle_t *cycle, void *conf); @@ -188,14 +188,13 @@ static int ngx_rtsig_del_connection(ngx_ } -int ngx_rtsig_process_events(ngx_log_t *log) +int ngx_rtsig_process_events(ngx_cycle_t *cycle) { int signo; ngx_int_t instance, i; size_t n; ngx_msec_t timer; ngx_err_t err; - ngx_cycle_t **cycle; siginfo_t si; struct timeval tv; struct timespec ts, *tp; @@ -216,7 +215,8 @@ int ngx_rtsig_process_events(ngx_log_t * tp = NULL; } - ngx_log_debug1(NGX_LOG_DEBUG_EVENT, log, 0, "rtsig timer: %d", timer); + ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0, + "rtsig timer: %d", timer); /* Linux sigwaitinfo() is sigtimedwait() with the NULL timeout pointer */ @@ -236,18 +236,18 @@ int ngx_rtsig_process_events(ngx_log_t * if (err) { ngx_log_error((err == NGX_EINTR) ? NGX_LOG_INFO : NGX_LOG_ALERT, - log, err, "sigtimedwait() failed"); + cycle->log, err, "sigtimedwait() failed"); return NGX_ERROR; } if (timer) { delta = ngx_elapsed_msec - delta; - ngx_log_debug2(NGX_LOG_DEBUG_EVENT, log, 0, + ngx_log_debug2(NGX_LOG_DEBUG_EVENT, cycle->log, 0, "rtsig timer: %d, delta: %d", timer, (int) delta); } - ngx_log_debug3(NGX_LOG_DEBUG_EVENT, log, 0, + ngx_log_debug3(NGX_LOG_DEBUG_EVENT, cycle->log, 0, "signo:%d fd:%d band:%X", signo, si.si_fd, si.si_band); rtscf = ngx_event_get_conf(ngx_cycle->conf_ctx, ngx_rtsig_module); @@ -255,6 +255,7 @@ int ngx_rtsig_process_events(ngx_log_t * if (signo == rtscf->signo) { /* TODO: old_cycles */ + c = &ngx_cycle->connections[si.si_fd]; /* TODO: stale signals */ @@ -274,7 +275,7 @@ int ngx_rtsig_process_events(ngx_log_t * } } else if (signo == SIGIO) { - ngx_log_error(NGX_LOG_ALERT, log, ngx_errno, + ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, "signal queue overflowed: " "SIGIO, fd:%d, band:%X", si.si_fd, si.si_band); @@ -284,7 +285,7 @@ int ngx_rtsig_process_events(ngx_log_t * sa.sa_handler = SIG_DFL; sigemptyset(&sa.sa_mask); if (sigaction(rtscf->signo, &sa, NULL) == -1) { - ngx_log_error(NGX_LOG_ALERT, log, ngx_errno, + ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, "sigaction(%d, SIG_DFL) failed", rtscf->signo); } @@ -297,7 +298,7 @@ int ngx_rtsig_process_events(ngx_log_t * } else { - ngx_log_error(NGX_LOG_ALERT, log, 0, + ngx_log_error(NGX_LOG_ALERT, cycle->log, 0, "sigtimedwait() returned unexpected signal: %d", signo); return NGX_ERROR; } @@ -310,9 +311,9 @@ int ngx_rtsig_process_events(ngx_log_t * } -static int ngx_rtsig_process_overflow(ngx_log_t *log) +static int ngx_rtsig_process_overflow(ngx_cycle_t *cycle) { - if (ngx_poll_module_ctx.actions.process(log) == NGX_OK) { + if (ngx_poll_module_ctx.actions.process(cycle) == NGX_OK) { ngx_event_actions = ngx_rtsig_module_ctx.actions; ngx_event_flags = NGX_USE_SIGIO_EVENT; } diff --git a/src/event/ngx_event.c b/src/event/ngx_event.c --- a/src/event/ngx_event.c +++ b/src/event/ngx_event.c @@ -155,9 +155,9 @@ static ngx_int_t ngx_event_module_init(n return NGX_OK; } - ngx_accept_mutex_ptr = mmap(NULL, sizeof(ngx_atomic_t), - PROT_READ|PROT_WRITE, - MAP_ANON|MAP_SHARED, -1, 0); + ngx_accept_mutex_ptr = (ngx_atomic_t *) mmap(NULL, sizeof(ngx_atomic_t), + PROT_READ|PROT_WRITE, + MAP_ANON|MAP_SHARED, -1, 0); if (ngx_accept_mutex_ptr == NULL) { ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, diff --git a/src/http/modules/proxy/ngx_http_proxy_handler.c b/src/http/modules/proxy/ngx_http_proxy_handler.c --- a/src/http/modules/proxy/ngx_http_proxy_handler.c +++ b/src/http/modules/proxy/ngx_http_proxy_handler.c @@ -381,6 +381,9 @@ void ngx_http_proxy_check_broken_connect p = ngx_http_get_module_ctx(r, ngx_http_proxy_module); #if (HAVE_KQUEUE) + + /* TODO: KEVENT_EVENT */ + if (ev->kq_eof) { ev->eof = 1; @@ -405,6 +408,44 @@ void ngx_http_proxy_check_broken_connect ngx_http_proxy_finalize_request(p, NGX_HTTP_CLIENT_CLOSED_REQUEST); } } + +#else + + n = recv(c->fd, buf, 1, MSG_PEEK); + + if (n > 0) { + /* TODO: delete level */ + return; + } + + if (n == -1) { + err = ngx_socket_errno; + if (err == NGX_EAGAIN) { + return; + } + + ev->error = 1; + + } else if (n == 0) { + err = 0; + ev->eof = 1; + } + + if (!p->cachable && p->upstream->peer.connection) { + ngx_log_error(NGX_LOG_INFO, ev->log, err, + "client have closed prematurely connection, " + "so upstream connection is closed too"); + ngx_http_proxy_finalize_request(p, NGX_HTTP_CLIENT_CLOSED_REQUEST); + return; + } + + ngx_log_error(NGX_LOG_INFO, ev->log, ev->err, + "client have closed prematurely connection"); + + if (p->upstream == NULL || p->upstream->peer.connection == NULL) { + ngx_http_proxy_finalize_request(p, NGX_HTTP_CLIENT_CLOSED_REQUEST); + } + #endif } diff --git a/src/http/ngx_http_request.c b/src/http/ngx_http_request.c --- a/src/http/ngx_http_request.c +++ b/src/http/ngx_http_request.c @@ -97,7 +97,7 @@ void ngx_http_init_connection(ngx_connec return; } - rev->next = ngx_posted_events; + rev->next = (ngx_event_t *) ngx_posted_events; ngx_posted_events = rev; ngx_mutex_unlock(ngx_posted_events_mutex); diff --git a/src/os/unix/ngx_errno.c b/src/os/unix/ngx_errno.c --- a/src/os/unix/ngx_errno.c +++ b/src/os/unix/ngx_errno.c @@ -43,7 +43,7 @@ ngx_int_t ngx_strerror_r(int err, char * str = strerror_r(err, errstr, size); if (str != errstr) { - return ngx_cpystrn(errstr, str, size) - errstr; + return ngx_cpystrn(errstr, str, size) - (u_char *) errstr; } for (len = 0; len < size; len++) { diff --git a/src/os/unix/ngx_freebsd_rfork_thread.c b/src/os/unix/ngx_freebsd_rfork_thread.c --- a/src/os/unix/ngx_freebsd_rfork_thread.c +++ b/src/os/unix/ngx_freebsd_rfork_thread.c @@ -26,7 +26,6 @@ */ -ngx_int_t ngx_threaded; char *ngx_freebsd_kern_usrstack; size_t ngx_thread_stack_size; diff --git a/src/os/unix/ngx_linux_config.h b/src/os/unix/ngx_linux_config.h --- a/src/os/unix/ngx_linux_config.h +++ b/src/os/unix/ngx_linux_config.h @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include /* TCP_CORK */ diff --git a/src/os/unix/ngx_process_cycle.c b/src/os/unix/ngx_process_cycle.c --- a/src/os/unix/ngx_process_cycle.c +++ b/src/os/unix/ngx_process_cycle.c @@ -15,6 +15,7 @@ ngx_int_t ngx_process; ngx_pid_t ngx_pid; ngx_pid_t ngx_new_binary; ngx_int_t ngx_inherited; +ngx_int_t ngx_threaded; sig_atomic_t ngx_reap; sig_atomic_t ngx_timer; diff --git a/src/os/unix/ngx_process_cycle.h b/src/os/unix/ngx_process_cycle.h --- a/src/os/unix/ngx_process_cycle.h +++ b/src/os/unix/ngx_process_cycle.h @@ -26,6 +26,7 @@ extern ngx_int_t ngx_process; extern ngx_pid_t ngx_pid; extern ngx_pid_t ngx_new_binary; extern ngx_int_t ngx_inherited; +extern ngx_int_t ngx_threaded; extern sig_atomic_t ngx_reap; extern sig_atomic_t ngx_timer; diff --git a/src/os/unix/ngx_readv_chain.c b/src/os/unix/ngx_readv_chain.c --- a/src/os/unix/ngx_readv_chain.c +++ b/src/os/unix/ngx_readv_chain.c @@ -135,7 +135,7 @@ ssize_t ngx_readv_chain(ngx_connection_t ssize_t ngx_readv_chain(ngx_connection_t *c, ngx_chain_t *chain) { - char *prev; + u_char *prev; ssize_t n, size; struct iovec *iov; ngx_err_t err; diff --git a/src/os/unix/ngx_recv.c b/src/os/unix/ngx_recv.c --- a/src/os/unix/ngx_recv.c +++ b/src/os/unix/ngx_recv.c @@ -112,7 +112,7 @@ ssize_t ngx_unix_recv(ngx_connection_t * #else /* ! NAVE_KQUEUE */ -ssize_t ngx_unix_recv(ngx_connection_t *c, char *buf, size_t size) +ssize_t ngx_unix_recv(ngx_connection_t *c, u_char *buf, size_t size) { ssize_t n; ngx_err_t err; diff --git a/src/os/unix/ngx_solaris_config.h b/src/os/unix/ngx_solaris_config.h --- a/src/os/unix/ngx_solaris_config.h +++ b/src/os/unix/ngx_solaris_config.h @@ -22,10 +22,11 @@ #include #include #include +#include +#include +#include #include /* FIONBIO */ #include /* INFTIM */ -#include -#include #include #include #include diff --git a/src/os/unix/ngx_thread.h b/src/os/unix/ngx_thread.h --- a/src/os/unix/ngx_thread.h +++ b/src/os/unix/ngx_thread.h @@ -102,9 +102,6 @@ ngx_int_t ngx_mutex_dolock(ngx_mutex_t * ngx_int_t ngx_mutex_unlock(ngx_mutex_t *m); -extern ngx_int_t ngx_threaded; - - #else /* !NGX_THREADS */ #define ngx_thread_volatile diff --git a/src/os/unix/ngx_time.c b/src/os/unix/ngx_time.c --- a/src/os/unix/ngx_time.c +++ b/src/os/unix/ngx_time.c @@ -20,72 +20,3 @@ void ngx_localtime(ngx_tm_t *tm) tm->ngx_tm_mon++; tm->ngx_tm_year += 1900; } - - - -#if 0 - -typedef struct { - int busy; - u_int_64 msec; - time_t sec; - tm; - http_time_len; - http_time[n]; -}; - -volatile *ngx_time_p; - -ngx_time() -{ - p = ngx_time_p; -} - -ngx_update_time() -{ - u_int64 msec; - struct timeval tv; - - gettimeofday(&tv, NULL); - - msec = (unsigned long) tv.tv_sec * 1000 + tv.tv_usec / 1000; - p = ngx_time_p; - - /* minimum can be for example 0, 10, 50 or 100 ms */ - if (tv_sec > p->sec || msec - p->msec >= minimum) { - old_p = p; - /* max_tries < max_slots - 10, - max_slots should be more than max of threads */ - for (/* void */; i < max_tries; i++) { - if (++p >= last_slot) - p = first_slot; - - if (!test_and_set(p->busy) - break; - } - - if (i == max_tries) { - ngx_log_error(); - return; - } - - if (tv_sec > p->sec) { - p->sec = tv.tv.sec; - p->msec = msec; - localtime_r(&tv.tv_sec, tm); - make http stirng; - - } else { - ngx_memcpy(p->sec, old_p->sec, sizeof() - offset_of(, sec)); - p->msec = msec; - } - - /* here can be too seldom and non-critical race condition */ - if (ngx_time_p == old_p) - ngx_time_p = p; - - unlock(p->busy); - } -} - -#endif diff --git a/src/os/win32/ngx_process_cycle.h b/src/os/win32/ngx_process_cycle.h --- a/src/os/win32/ngx_process_cycle.h +++ b/src/os/win32/ngx_process_cycle.h @@ -26,6 +26,7 @@ extern ngx_int_t ngx_process; extern ngx_pid_t ngx_pid; extern ngx_pid_t ngx_new_binary; extern ngx_int_t ngx_inherited; +extern ngx_int_t ngx_threaded; extern sig_atomic_t ngx_reap; extern sig_atomic_t ngx_timer;