comparison src/http/v2/ngx_http_v2_filter_module.c @ 6293:ec6b07be88a5

HTTP/2: reused HEADERS and CONTINUATION frames buffers.
author Valentin Bartenev <vbart@nginx.com>
date Fri, 13 Nov 2015 20:10:50 +0300
parents f72d3129cd35
children 11e019750adc
comparison
equal deleted inserted replaced
6292:f72d3129cd35 6293:ec6b07be88a5
622 622
623 b->last = ngx_http_v2_write_len_and_type(b->last, frame_size, type); 623 b->last = ngx_http_v2_write_len_and_type(b->last, frame_size, type);
624 *b->last++ = flags; 624 *b->last++ = flags;
625 b->last = ngx_http_v2_write_sid(b->last, stream->node->id); 625 b->last = ngx_http_v2_write_sid(b->last, stream->node->id);
626 626
627 b->tag = (ngx_buf_tag_t) &ngx_http_v2_module;
628
627 cl = ngx_alloc_chain_link(r->pool); 629 cl = ngx_alloc_chain_link(r->pool);
628 if (cl == NULL) { 630 if (cl == NULL) {
629 return NULL; 631 return NULL;
630 } 632 }
631 633
927 ngx_log_debug4(NGX_LOG_DEBUG_HTTP, stream->request->connection->log, 0, 929 ngx_log_debug4(NGX_LOG_DEBUG_HTTP, stream->request->connection->log, 0,
928 "http2:%ui create DATA frame %p: len:%uz flags:%ui", 930 "http2:%ui create DATA frame %p: len:%uz flags:%ui",
929 stream->node->id, frame, len, (ngx_uint_t) flags); 931 stream->node->id, frame, len, (ngx_uint_t) flags);
930 932
931 cl = ngx_chain_get_free_buf(stream->request->pool, 933 cl = ngx_chain_get_free_buf(stream->request->pool,
932 &stream->free_data_headers); 934 &stream->free_frame_headers);
933 if (cl == NULL) { 935 if (cl == NULL) {
934 return NULL; 936 return NULL;
935 } 937 }
936 938
937 buf = cl->buf; 939 buf = cl->buf;
944 } 946 }
945 947
946 buf->end = buf->start + NGX_HTTP_V2_FRAME_HEADER_SIZE; 948 buf->end = buf->start + NGX_HTTP_V2_FRAME_HEADER_SIZE;
947 buf->last = buf->end; 949 buf->last = buf->end;
948 950
949 buf->tag = (ngx_buf_tag_t) &ngx_http_v2_filter_get_data_frame; 951 buf->tag = (ngx_buf_tag_t) &ngx_http_v2_module;
950 buf->memory = 1; 952 buf->memory = 1;
951 } 953 }
952 954
953 buf->pos = buf->start; 955 buf->pos = buf->start;
954 buf->last = buf->pos; 956 buf->last = buf->pos;
1052 1054
1053 static ngx_int_t 1055 static ngx_int_t
1054 ngx_http_v2_headers_frame_handler(ngx_http_v2_connection_t *h2c, 1056 ngx_http_v2_headers_frame_handler(ngx_http_v2_connection_t *h2c,
1055 ngx_http_v2_out_frame_t *frame) 1057 ngx_http_v2_out_frame_t *frame)
1056 { 1058 {
1057 ngx_chain_t *cl; 1059 ngx_chain_t *cl, *ln;
1058 ngx_http_v2_stream_t *stream; 1060 ngx_http_v2_stream_t *stream;
1059 1061
1060 stream = frame->stream; 1062 stream = frame->stream;
1061 cl = frame->first; 1063 cl = frame->first;
1062 1064
1069 stream->node->id, frame); 1071 stream->node->id, frame);
1070 1072
1071 return NGX_AGAIN; 1073 return NGX_AGAIN;
1072 } 1074 }
1073 1075
1076 ln = cl->next;
1077
1078 if (cl->buf->tag == (ngx_buf_tag_t) &ngx_http_v2_module) {
1079 cl->next = stream->free_frame_headers;
1080 stream->free_frame_headers = cl;
1081
1082 } else {
1083 cl->next = stream->free_bufs;
1084 stream->free_bufs = cl;
1085 }
1086
1074 if (cl == frame->last) { 1087 if (cl == frame->last) {
1075 break; 1088 break;
1076 } 1089 }
1077 1090
1078 cl = cl->next; 1091 cl = ln;
1079 } 1092 }
1080 1093
1081 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, h2c->connection->log, 0, 1094 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, h2c->connection->log, 0,
1082 "http2:%ui HEADERS frame %p was sent", 1095 "http2:%ui HEADERS frame %p was sent",
1083 stream->node->id, frame); 1096 stream->node->id, frame);
1084 1097
1085 ngx_free_chain(stream->request->pool, frame->first);
1086
1087 ngx_http_v2_handle_frame(stream, frame); 1098 ngx_http_v2_handle_frame(stream, frame);
1088 1099
1089 ngx_http_v2_handle_stream(h2c, stream); 1100 ngx_http_v2_handle_stream(h2c, stream);
1090 1101
1091 return NGX_OK; 1102 return NGX_OK;
1102 1113
1103 stream = frame->stream; 1114 stream = frame->stream;
1104 1115
1105 cl = frame->first; 1116 cl = frame->first;
1106 1117
1107 if (cl->buf->tag == (ngx_buf_tag_t) &ngx_http_v2_filter_get_data_frame) { 1118 if (cl->buf->tag == (ngx_buf_tag_t) &ngx_http_v2_module) {
1108 1119
1109 if (cl->buf->pos != cl->buf->last) { 1120 if (cl->buf->pos != cl->buf->last) {
1110 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, h2c->connection->log, 0, 1121 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, h2c->connection->log, 0,
1111 "http2:%ui DATA frame %p was sent partially", 1122 "http2:%ui DATA frame %p was sent partially",
1112 stream->node->id, frame); 1123 stream->node->id, frame);
1114 return NGX_AGAIN; 1125 return NGX_AGAIN;
1115 } 1126 }
1116 1127
1117 ln = cl->next; 1128 ln = cl->next;
1118 1129
1119 cl->next = stream->free_data_headers; 1130 cl->next = stream->free_frame_headers;
1120 stream->free_data_headers = cl; 1131 stream->free_frame_headers = cl;
1121 1132
1122 if (cl == frame->last) { 1133 if (cl == frame->last) {
1123 goto done; 1134 goto done;
1124 } 1135 }
1125 1136