diff options
author | Igor Sysoev <igor@sysoev.ru> | 2007-03-19 16:20:15 +0300 |
---|---|---|
committer | Igor Sysoev <igor@sysoev.ru> | 2007-03-19 16:20:15 +0300 |
commit | 4ddeff4956a93efce34105588153f591f3fcfcbc (patch) | |
tree | 63e5d49a946d447ca0783647d939fe9bdf173b9e | |
parent | e1f43ce292b0ca463748e13b067ea36bbe8ca9bc (diff) |
close keep-alive connections in the shuting down processes
-rw-r--r-- | src/core/ngx_connection.h | 3 | ||||
-rw-r--r-- | src/http/ngx_http_request.c | 6 | ||||
-rw-r--r-- | src/os/unix/ngx_process_cycle.c | 27 |
3 files changed, 30 insertions, 6 deletions
diff --git a/src/core/ngx_connection.h b/src/core/ngx_connection.h index 1694dd451..a2ae690f5 100644 --- a/src/core/ngx_connection.h +++ b/src/core/ngx_connection.h @@ -143,6 +143,9 @@ struct ngx_connection_s { unsigned error:1; unsigned destroyed:1; + unsigned idle:1; + unsigned close:1; + unsigned sendfile:1; unsigned sndlowat:1; unsigned tcp_nodelay:2; /* ngx_connection_tcp_nodelay_e */ diff --git a/src/http/ngx_http_request.c b/src/http/ngx_http_request.c index 96286597b..afc1d644d 100644 --- a/src/http/ngx_http_request.c +++ b/src/http/ngx_http_request.c @@ -2032,6 +2032,8 @@ ngx_http_set_keepalive(ngx_http_request_t *r) r->http_state = NGX_HTTP_KEEPALIVE_STATE; #endif + c->idle = 1; + if (rev->ready) { ngx_http_keepalive_handler(rev); } @@ -2050,7 +2052,7 @@ ngx_http_keepalive_handler(ngx_event_t *rev) ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http keepalive handler"); - if (rev->timedout) { + if (rev->timedout || c->close) { ngx_http_close_connection(c); return; } @@ -2139,6 +2141,8 @@ ngx_http_keepalive_handler(ngx_event_t *rev) c->log->handler = ngx_http_log_error; c->log->action = "reading client request line"; + c->idle = 0; + ngx_http_init_request(rev); } diff --git a/src/os/unix/ngx_process_cycle.c b/src/os/unix/ngx_process_cycle.c index 1b6a0804c..90993966d 100644 --- a/src/os/unix/ngx_process_cycle.c +++ b/src/os/unix/ngx_process_cycle.c @@ -664,6 +664,8 @@ ngx_master_process_exit(ngx_cycle_t *cycle) static void ngx_worker_process_cycle(ngx_cycle_t *cycle, void *data) { + ngx_uint_t i; + ngx_connection_t *c; #if (NGX_THREADS) ngx_int_t n; ngx_err_t err; @@ -717,12 +719,27 @@ ngx_worker_process_cycle(ngx_cycle_t *cycle, void *data) #endif for ( ;; ) { - if (ngx_exiting - && ngx_event_timer_rbtree.root == ngx_event_timer_rbtree.sentinel) - { - ngx_log_error(NGX_LOG_NOTICE, cycle->log, 0, "exiting"); - ngx_worker_process_exit(cycle); + if (ngx_exiting) { + + c = cycle->connections; + + for (i = 0; i < cycle->connection_n; i++) { + + /* THREAD: lock */ + + if (c[i].fd != -1 && c[i].idle) { + c[i].close = 1; + c[i].read->handler(c[i].read); + } + } + + if (ngx_event_timer_rbtree.root == ngx_event_timer_rbtree.sentinel) + { + ngx_log_error(NGX_LOG_NOTICE, cycle->log, 0, "exiting"); + + ngx_worker_process_exit(cycle); + } } ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0, "worker cycle"); |