summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorValentin Bartenev <vbart@nginx.com>2015-11-13 20:10:50 +0300
committerValentin Bartenev <vbart@nginx.com>2015-11-13 20:10:50 +0300
commita52bbefd84f718af15efc8176bc1ee6a461c4db4 (patch)
tree9cb42fb14cf09c2250c45563004600248ce1544f
parent548e31f6084e2a90d0befcb5c8ff549466a111d3 (diff)
HTTP/2: reused HEADERS and CONTINUATION frames buffers.
-rw-r--r--src/http/v2/ngx_http_v2.h2
-rw-r--r--src/http/v2/ngx_http_v2_filter_module.c29
2 files changed, 21 insertions, 10 deletions
diff --git a/src/http/v2/ngx_http_v2.h b/src/http/v2/ngx_http_v2.h
index c3d409af..4c63b216 100644
--- a/src/http/v2/ngx_http_v2.h
+++ b/src/http/v2/ngx_http_v2.h
@@ -178,7 +178,7 @@ struct ngx_http_v2_stream_s {
size_t recv_window;
ngx_http_v2_out_frame_t *free_frames;
- ngx_chain_t *free_data_headers;
+ ngx_chain_t *free_frame_headers;
ngx_chain_t *free_bufs;
ngx_queue_t queue;
diff --git a/src/http/v2/ngx_http_v2_filter_module.c b/src/http/v2/ngx_http_v2_filter_module.c
index aea5933f..ed30fe56 100644
--- a/src/http/v2/ngx_http_v2_filter_module.c
+++ b/src/http/v2/ngx_http_v2_filter_module.c
@@ -624,6 +624,8 @@ ngx_http_v2_create_headers_frame(ngx_http_request_t *r, u_char *pos,
*b->last++ = flags;
b->last = ngx_http_v2_write_sid(b->last, stream->node->id);
+ b->tag = (ngx_buf_tag_t) &ngx_http_v2_module;
+
cl = ngx_alloc_chain_link(r->pool);
if (cl == NULL) {
return NULL;
@@ -929,7 +931,7 @@ ngx_http_v2_filter_get_data_frame(ngx_http_v2_stream_t *stream,
stream->node->id, frame, len, (ngx_uint_t) flags);
cl = ngx_chain_get_free_buf(stream->request->pool,
- &stream->free_data_headers);
+ &stream->free_frame_headers);
if (cl == NULL) {
return NULL;
}
@@ -946,7 +948,7 @@ ngx_http_v2_filter_get_data_frame(ngx_http_v2_stream_t *stream,
buf->end = buf->start + NGX_HTTP_V2_FRAME_HEADER_SIZE;
buf->last = buf->end;
- buf->tag = (ngx_buf_tag_t) &ngx_http_v2_filter_get_data_frame;
+ buf->tag = (ngx_buf_tag_t) &ngx_http_v2_module;
buf->memory = 1;
}
@@ -1054,7 +1056,7 @@ static ngx_int_t
ngx_http_v2_headers_frame_handler(ngx_http_v2_connection_t *h2c,
ngx_http_v2_out_frame_t *frame)
{
- ngx_chain_t *cl;
+ ngx_chain_t *cl, *ln;
ngx_http_v2_stream_t *stream;
stream = frame->stream;
@@ -1071,19 +1073,28 @@ ngx_http_v2_headers_frame_handler(ngx_http_v2_connection_t *h2c,
return NGX_AGAIN;
}
+ ln = cl->next;
+
+ if (cl->buf->tag == (ngx_buf_tag_t) &ngx_http_v2_module) {
+ cl->next = stream->free_frame_headers;
+ stream->free_frame_headers = cl;
+
+ } else {
+ cl->next = stream->free_bufs;
+ stream->free_bufs = cl;
+ }
+
if (cl == frame->last) {
break;
}
- cl = cl->next;
+ cl = ln;
}
ngx_log_debug2(NGX_LOG_DEBUG_HTTP, h2c->connection->log, 0,
"http2:%ui HEADERS frame %p was sent",
stream->node->id, frame);
- ngx_free_chain(stream->request->pool, frame->first);
-
ngx_http_v2_handle_frame(stream, frame);
ngx_http_v2_handle_stream(h2c, stream);
@@ -1104,7 +1115,7 @@ ngx_http_v2_data_frame_handler(ngx_http_v2_connection_t *h2c,
cl = frame->first;
- if (cl->buf->tag == (ngx_buf_tag_t) &ngx_http_v2_filter_get_data_frame) {
+ if (cl->buf->tag == (ngx_buf_tag_t) &ngx_http_v2_module) {
if (cl->buf->pos != cl->buf->last) {
ngx_log_debug2(NGX_LOG_DEBUG_HTTP, h2c->connection->log, 0,
@@ -1116,8 +1127,8 @@ ngx_http_v2_data_frame_handler(ngx_http_v2_connection_t *h2c,
ln = cl->next;
- cl->next = stream->free_data_headers;
- stream->free_data_headers = cl;
+ cl->next = stream->free_frame_headers;
+ stream->free_frame_headers = cl;
if (cl == frame->last) {
goto done;