diff options
Diffstat (limited to 'src/http')
-rw-r--r-- | src/http/modules/ngx_http_range_filter.c | 38 | ||||
-rw-r--r-- | src/http/modules/ngx_http_stub_status_module.c | 8 | ||||
-rw-r--r-- | src/http/ngx_http_header_filter.c | 33 | ||||
-rw-r--r-- | src/http/ngx_http_log_handler.c | 11 | ||||
-rw-r--r-- | src/http/ngx_http_request.c | 33 |
5 files changed, 70 insertions, 53 deletions
diff --git a/src/http/modules/ngx_http_range_filter.c b/src/http/modules/ngx_http_range_filter.c index 8f98719a1..1eb4cc617 100644 --- a/src/http/modules/ngx_http_range_filter.c +++ b/src/http/modules/ngx_http_range_filter.c @@ -105,14 +105,15 @@ static ngx_http_output_header_filter_pt ngx_http_next_header_filter; static ngx_http_output_body_filter_pt ngx_http_next_body_filter; -static ngx_int_t ngx_http_range_header_filter(ngx_http_request_t *r) +static ngx_int_t +ngx_http_range_header_filter(ngx_http_request_t *r) { u_char *p; size_t len; off_t start, end; ngx_int_t rc; - uint32_t boundary; ngx_uint_t suffix, i; + ngx_atomic_int_t boundary; ngx_table_elt_t *content_range; ngx_http_range_t *range; ngx_http_range_filter_ctx_t *ctx; @@ -328,7 +329,8 @@ static ngx_int_t ngx_http_range_header_filter(ngx_http_request_t *r) sizeof(ngx_http_range_filter_ctx_t), NGX_ERROR); - len = sizeof(CRLF "--0123456789" CRLF "Content-Type: ") - 1 + len = sizeof(CRLF "--") - 1 + NGX_ATOMIC_T_LEN + + sizeof(CRLF "Content-Type: ") - 1 + r->headers_out.content_type->value.len + sizeof(CRLF "Content-Range: bytes ") - 1; @@ -340,7 +342,7 @@ static ngx_int_t ngx_http_range_header_filter(ngx_http_request_t *r) return NGX_ERROR; } - boundary = (uint32_t) ngx_next_temp_number(0); + boundary = ngx_next_temp_number(0); /* * The boundary header of the range: @@ -352,7 +354,7 @@ static ngx_int_t ngx_http_range_header_filter(ngx_http_request_t *r) if (r->headers_out.charset.len) { ctx->boundary_header.len = ngx_sprintf(ctx->boundary_header.data, - CRLF "--%010ud" CRLF + CRLF "--%0muA" CRLF "Content-Type: %V; charset=%V" CRLF "Content-Range: bytes ", boundary, @@ -364,7 +366,7 @@ static ngx_int_t ngx_http_range_header_filter(ngx_http_request_t *r) } else { ctx->boundary_header.len = ngx_sprintf(ctx->boundary_header.data, - CRLF "--%010ud" CRLF + CRLF "--%0muA" CRLF "Content-Type: %V" CRLF "Content-Range: bytes ", boundary, @@ -373,8 +375,9 @@ static ngx_int_t ngx_http_range_header_filter(ngx_http_request_t *r) } r->headers_out.content_type->value.data = - ngx_palloc(r->pool, sizeof("Content-Type: multipart/byteranges; " - "boundary=0123456789") - 1); + ngx_palloc(r->pool, + sizeof("Content-Type: multipart/byteranges; boundary=") - 1 + + NGX_ATOMIC_T_LEN); if (r->headers_out.content_type->value.data == NULL) { return NGX_ERROR; @@ -384,12 +387,14 @@ static ngx_int_t ngx_http_range_header_filter(ngx_http_request_t *r) r->headers_out.content_type->value.len = ngx_sprintf(r->headers_out.content_type->value.data, - "multipart/byteranges; boundary=%010ud", + "multipart/byteranges; boundary=%0muA", boundary) - r->headers_out.content_type->value.data; + /* the size of the last boundary CRLF "--0123456789--" CRLF */ - len = sizeof(CRLF "--0123456789--" CRLF) - 1; + + len = sizeof(CRLF "--") - 1 + NGX_ATOMIC_T_LEN + sizeof("--" CRLF) - 1; range = r->headers_out.ranges.elts; for (i = 0; i < r->headers_out.ranges.nelts; i++) { @@ -420,8 +425,8 @@ static ngx_int_t ngx_http_range_header_filter(ngx_http_request_t *r) } -static ngx_int_t ngx_http_range_body_filter(ngx_http_request_t *r, - ngx_chain_t *in) +static ngx_int_t +ngx_http_range_body_filter(ngx_http_request_t *r, ngx_chain_t *in) { ngx_uint_t i; ngx_buf_t *b; @@ -525,7 +530,8 @@ static ngx_int_t ngx_http_range_body_filter(ngx_http_request_t *r, b->temporary = 1; b->last_buf = 1; - b->pos = ngx_palloc(r->pool, sizeof(CRLF "--0123456789--" CRLF) - 1); + b->pos = ngx_palloc(r->pool, sizeof(CRLF "--") - 1 + NGX_ATOMIC_T_LEN + + sizeof("--" CRLF) - 1); if (b->pos == NULL) { return NGX_ERROR; } @@ -552,7 +558,8 @@ static ngx_int_t ngx_http_range_body_filter(ngx_http_request_t *r, } -static ngx_int_t ngx_http_range_header_filter_init(ngx_cycle_t *cycle) +static ngx_int_t +ngx_http_range_header_filter_init(ngx_cycle_t *cycle) { ngx_http_next_header_filter = ngx_http_top_header_filter; ngx_http_top_header_filter = ngx_http_range_header_filter; @@ -561,7 +568,8 @@ static ngx_int_t ngx_http_range_header_filter_init(ngx_cycle_t *cycle) } -static ngx_int_t ngx_http_range_body_filter_init(ngx_cycle_t *cycle) +static ngx_int_t +ngx_http_range_body_filter_init(ngx_cycle_t *cycle) { ngx_http_next_body_filter = ngx_http_top_body_filter; ngx_http_top_body_filter = ngx_http_range_body_filter; diff --git a/src/http/modules/ngx_http_stub_status_module.c b/src/http/modules/ngx_http_stub_status_module.c index 3a35fe910..834beaa92 100644 --- a/src/http/modules/ngx_http_stub_status_module.c +++ b/src/http/modules/ngx_http_stub_status_module.c @@ -102,15 +102,15 @@ static ngx_int_t ngx_http_status_handler(ngx_http_request_t *r) rd = *ngx_stat_reading; wr = *ngx_stat_writing; - b->last = ngx_sprintf(b->last, "Active connections: %d \n", ac); + b->last = ngx_sprintf(b->last, "Active connections: %D \n", ac); b->last = ngx_cpymem(b->last, "server accepts handled requests\n", sizeof("server accepts handled requests\n") - 1); - b->last = ngx_sprintf(b->last, " %d %d %d \n", ap, hn, rq); + b->last = ngx_sprintf(b->last, " %D %D %D \n", ap, hn, rq); - b->last = ngx_sprintf(b->last, "Reading: %d Writing: %d Waiting: %d \n", - rd, wr, ac - (rd + wr)); + b->last = ngx_sprintf(b->last, "Reading: %D Writing: %D Waiting: %d \n", + rd, wr, ac - (rd + wr)); r->headers_out.status = NGX_HTTP_OK; r->headers_out.content_length_n = b->last - b->pos; diff --git a/src/http/ngx_http_header_filter.c b/src/http/ngx_http_header_filter.c index 3610b1e3a..ea0907ff1 100644 --- a/src/http/ngx_http_header_filter.c +++ b/src/http/ngx_http_header_filter.c @@ -117,7 +117,8 @@ ngx_http_header_t ngx_http_headers_out[] = { }; -static ngx_int_t ngx_http_header_filter(ngx_http_request_t *r) +static ngx_int_t +ngx_http_header_filter(ngx_http_request_t *r) { u_char *p; size_t len; @@ -146,8 +147,9 @@ static ngx_int_t ngx_http_header_filter(ngx_http_request_t *r) } } - /* 2 is for trailing "\r\n" and 2 is for "\r\n" in the end of header */ - len = sizeof("HTTP/1.x ") - 1 + 2 + 2; + len = sizeof("HTTP/1.x ") - 1 + sizeof(CRLF) - 1 + /* the end of the header */ + + sizeof(CRLF) - 1; /* status line */ @@ -279,8 +281,8 @@ static ngx_int_t ngx_http_header_filter(ngx_http_request_t *r) continue; } - /* 2 is for ": " and 2 is for "\r\n" */ - len += header[i].key.len + 2 + header[i].value.len + 2; + len += header[i].key.len + sizeof(": ") - 1 + header[i].value.len + + sizeof(CRLF) - 1; } if (!(b = ngx_create_temp_buf(r->pool, len))) { @@ -299,7 +301,7 @@ static ngx_int_t ngx_http_header_filter(ngx_http_request_t *r) b->last = ngx_cpymem(b->last, http_codes[status].data, http_codes[status].len); } - *(b->last++) = CR; *(b->last++) = LF; + *b->last++ = CR; *b->last++ = LF; if (!(r->headers_out.server && r->headers_out.server->key.len)) { b->last = ngx_cpymem(b->last, server_string, sizeof(server_string) - 1); @@ -310,7 +312,7 @@ static ngx_int_t ngx_http_header_filter(ngx_http_request_t *r) b->last = ngx_cpymem(b->last, ngx_cached_http_time.data, ngx_cached_http_time.len); - *(b->last++) = CR; *(b->last++) = LF; + *b->last++ = CR; *b->last++ = LF; } if (r->headers_out.content_length == NULL) { @@ -337,7 +339,7 @@ static ngx_int_t ngx_http_header_filter(ngx_http_request_t *r) r->headers_out.content_type->value.data = p; } - *(b->last++) = CR; *(b->last++) = LF; + *b->last++ = CR; *b->last++ = LF; } if (r->headers_out.location @@ -360,7 +362,7 @@ static ngx_int_t ngx_http_header_filter(ngx_http_request_t *r) r->headers_out.location->value.len = b->last - p; r->headers_out.location->value.data = p; - *(b->last++) = CR; *(b->last++) = LF; + *b->last++ = CR; *b->last++ = LF; } if (!(r->headers_out.last_modified && r->headers_out.last_modified->key.len) @@ -370,7 +372,7 @@ static ngx_int_t ngx_http_header_filter(ngx_http_request_t *r) sizeof("Last-Modified: ") - 1); b->last = ngx_http_time(b->last, r->headers_out.last_modified_time); - *(b->last++) = CR; *(b->last++) = LF; + *b->last++ = CR; *b->last++ = LF; } if (r->chunked) { @@ -412,20 +414,20 @@ static ngx_int_t ngx_http_header_filter(ngx_http_request_t *r) } b->last = ngx_cpymem(b->last, header[i].key.data, header[i].key.len); - *(b->last++) = ':' ; *(b->last++) = ' ' ; + *b->last++ = ':' ; *b->last++ = ' ' ; b->last = ngx_cpymem(b->last, header[i].value.data, header[i].value.len); - *(b->last++) = CR; *(b->last++) = LF; + *b->last++ = CR; *b->last++ = LF; } #if (NGX_DEBUG) - *(b->last) = '\0'; + *b->last = '\0'; ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, "%s\n", b->pos); #endif /* the end of HTTP header */ - *(b->last++) = CR; *(b->last++) = LF; + *b->last++ = CR; *b->last++ = LF; r->header_size = b->last - b->pos; @@ -444,7 +446,8 @@ static ngx_int_t ngx_http_header_filter(ngx_http_request_t *r) } -static ngx_int_t ngx_http_header_filter_init(ngx_cycle_t *cycle) +static ngx_int_t +ngx_http_header_filter_init(ngx_cycle_t *cycle) { ngx_http_top_header_filter = ngx_http_header_filter; diff --git a/src/http/ngx_http_log_handler.c b/src/http/ngx_http_log_handler.c index 0d031fe0d..148246f64 100644 --- a/src/http/ngx_http_log_handler.c +++ b/src/http/ngx_http_log_handler.c @@ -135,7 +135,8 @@ static ngx_str_t ngx_http_combined_fmt = ngx_http_log_op_name_t ngx_http_log_fmt_ops[] = { { ngx_string("addr"), INET_ADDRSTRLEN - 1, NULL, NULL, ngx_http_log_addr }, - { ngx_string("conn"), NGX_INT32_LEN, NULL, NULL, ngx_http_log_connection }, + { ngx_string("conn"), NGX_ATOMIC_T_LEN, NULL, NULL, + ngx_http_log_connection }, { ngx_string("pipe"), 1, NULL, NULL, ngx_http_log_pipe }, { ngx_string("time"), sizeof("28/Sep/1970:12:00:00 +0600") - 1, NULL, NULL, ngx_http_log_time }, @@ -143,13 +144,13 @@ ngx_http_log_op_name_t ngx_http_log_fmt_ops[] = { { ngx_string("status"), 3, NULL, NULL, ngx_http_log_status }, { ngx_string("length"), NGX_OFF_T_LEN, NULL, NULL, ngx_http_log_length }, { ngx_string("apache_length"), NGX_OFF_T_LEN, - NULL, NULL, ngx_http_log_apache_length }, + NULL, NULL, ngx_http_log_apache_length }, { ngx_string("request_length"), NGX_SIZE_T_LEN, - NULL, NULL, ngx_http_log_request_length }, + NULL, NULL, ngx_http_log_request_length }, { ngx_string("request"), 0, NULL, - ngx_http_log_request_getlen, - ngx_http_log_request }, + ngx_http_log_request_getlen, + ngx_http_log_request }, { ngx_string("i"), 0, ngx_http_log_header_in_compile, ngx_http_log_header_in_getlen, diff --git a/src/http/ngx_http_request.c b/src/http/ngx_http_request.c index a6046f1bf..f4908476c 100644 --- a/src/http/ngx_http_request.c +++ b/src/http/ngx_http_request.c @@ -138,6 +138,7 @@ void ngx_http_init_connection(ngx_connection_t *c) if (ngx_accept_mutex) { if (ngx_mutex_lock(ngx_posted_events_mutex) == NGX_ERROR) { + ngx_http_close_connection(c); return; } @@ -145,11 +146,15 @@ void ngx_http_init_connection(ngx_connection_t *c) ngx_post_event(rev); ngx_mutex_unlock(ngx_posted_events_mutex); + +#if (NGX_STAT_STUB) + ngx_atomic_inc(ngx_stat_reading); +#endif return; } #if (NGX_STAT_STUB) - (*ngx_stat_reading)++; + ngx_atomic_inc(ngx_stat_reading); #endif ngx_http_init_request(rev); @@ -176,7 +181,7 @@ void ngx_http_init_connection(ngx_connection_t *c) #endif #if (NGX_STAT_STUB) - (*ngx_stat_reading)++; + ngx_atomic_inc(ngx_stat_reading); #endif } @@ -205,7 +210,7 @@ static void ngx_http_init_request(ngx_event_t *rev) ngx_log_error(NGX_LOG_INFO, c->log, NGX_ETIMEDOUT, "client timed out"); #if (NGX_STAT_STUB) - (*ngx_stat_reading)--; + ngx_atomic_dec(ngx_stat_reading); #endif ngx_http_close_connection(c); @@ -217,14 +222,14 @@ static void ngx_http_init_request(ngx_event_t *rev) if (hc) { #if (NGX_STAT_STUB) - (*ngx_stat_reading)++; + ngx_atomic_inc(ngx_stat_reading); #endif } else { if (!(hc = ngx_pcalloc(c->pool, sizeof(ngx_http_connection_t)))) { #if (NGX_STAT_STUB) - (*ngx_stat_reading)--; + ngx_atomic_dec(ngx_stat_reading); #endif ngx_http_close_connection(c); @@ -247,7 +252,7 @@ static void ngx_http_init_request(ngx_event_t *rev) if (!(r = ngx_pcalloc(c->pool, sizeof(ngx_http_request_t)))) { #if (NGX_STAT_STUB) - (*ngx_stat_reading)--; + ngx_atomic_dec(ngx_stat_reading); #endif ngx_http_close_connection(c); @@ -258,7 +263,7 @@ static void ngx_http_init_request(ngx_event_t *rev) } #if (NGX_STAT_STUB) - (*ngx_stat_reading)--; + ngx_atomic_dec(ngx_stat_reading); #endif c->data = r; @@ -427,9 +432,9 @@ static void ngx_http_init_request(ngx_event_t *rev) r->http_state = NGX_HTTP_READING_REQUEST_STATE; #if (NGX_STAT_STUB) - (*ngx_stat_reading)++; + ngx_atomic_inc(ngx_stat_reading); r->stat_reading = 1; - (*ngx_stat_requests)++; + ngx_atomic_inc(ngx_stat_requests); #endif rev->event_handler(rev); @@ -829,9 +834,9 @@ static void ngx_http_process_request_headers(ngx_event_t *rev) } #if (NGX_STAT_STUB) - (*ngx_stat_reading)--; + ngx_atomic_dec(ngx_stat_reading); r->stat_reading = 0; - (*ngx_stat_writing)++; + ngx_atomic_inc(ngx_stat_writing); r->stat_writing = 1; #endif @@ -2076,11 +2081,11 @@ void ngx_http_close_request(ngx_http_request_t *r, int error) #if (NGX_STAT_STUB) if (r->stat_reading) { - (*ngx_stat_reading)--; + ngx_atomic_dec(ngx_stat_reading); } if (r->stat_writing) { - (*ngx_stat_writing)--; + ngx_atomic_dec(ngx_stat_writing); } #endif @@ -2203,7 +2208,7 @@ void ngx_http_close_connection(ngx_connection_t *c) #endif #if (NGX_STAT_STUB) - (*ngx_stat_active)--; + ngx_atomic_dec(ngx_stat_active); #endif pool = c->pool; |