diff --git a/src/event/ngx_event_timer.c b/src/event/ngx_event_timer.c index 5663f5481..8b2616160 100644 --- a/src/event/ngx_event_timer.c +++ b/src/event/ngx_event_timer.c @@ -14,6 +14,7 @@ ngx_event_t *ngx_timer_queue; int ngx_timer_hash_size; +static int ngx_timer_cur_queue; int ngx_event_init_timer(ngx_log_t *log) @@ -21,6 +22,7 @@ int ngx_event_init_timer(ngx_log_t *log) int i; ngx_timer_hash_size = NGX_TIMER_HASH_SIZE; + ngx_timer_cur_queue = 0; ngx_test_null(ngx_timer_queue, ngx_alloc(ngx_timer_hash_size * sizeof(ngx_event_t), log), @@ -37,7 +39,6 @@ int ngx_event_init_timer(ngx_log_t *log) void ngx_event_add_timer(ngx_event_t *ev, ngx_msec_t timer) { - int n; ngx_event_t *e; #if (NGX_DEBUG_EVENT) @@ -50,18 +51,22 @@ void ngx_event_add_timer(ngx_event_t *ev, ngx_msec_t timer) return; } - n = timer % ngx_timer_hash_size; #if (NGX_DEBUG_EVENT) - ngx_log_debug(ev->log, "timer slot: %d" _ n); + ngx_log_debug(ev->log, "timer slot: %d" _ ngx_timer_cur_queue); #endif - for (e = ngx_timer_queue[n].timer_next; - e != &ngx_timer_queue[n] && timer > e->timer_delta; + for (e = ngx_timer_queue[ngx_timer_cur_queue].timer_next; + e != &ngx_timer_queue[ngx_timer_cur_queue] && timer > e->timer_delta; e = e->timer_next) { timer -= e->timer_delta; } + ngx_timer_cur_queue++; + if (ngx_timer_cur_queue >= ngx_timer_hash_size) { + ngx_timer_cur_queue = 0; + } + ev->timer_delta = timer; ev->timer_next = e; diff --git a/src/http/ngx_http_event.c b/src/http/ngx_http_event.c index b30050561..679210558 100644 --- a/src/http/ngx_http_event.c +++ b/src/http/ngx_http_event.c @@ -241,16 +241,27 @@ static int ngx_http_process_request_header(ngx_event_t *ev) } while (rc == NGX_AGAIN && r->header_in->pos.mem < r->header_in->last.mem); - if (r->header_timeout) { - r->header_timeout = 0; - ngx_del_timer(ev); - ngx_add_timer(ev, ngx_http_client_header_timeout); - } + if (rc == NGX_OK) { + /* HTTP header done */ + + if (r->header_timeout) { + r->header_timeout = 0; + ngx_del_timer(ev); + ngx_add_timer(ev, ngx_http_client_header_timeout); + } - if (rc == NGX_OK) return ngx_http_event_request_handler(r); - else + + } else { + + if (r->header_timeout) { + r->header_timeout = 0; + ngx_del_timer(ev); + ngx_add_timer(ev, ngx_http_client_header_timeout); + } + return rc; + } }