comparison src/http/v3/ngx_http_v3_request.c @ 8838:d6e191a583cc quic

HTTP/3: bulk parse functions. Previously HTTP/3 streams were parsed by one character. Now all parse functions receive buffers. This should optimize parsing time and CPU load.
author Roman Arutyunyan <arut@nginx.com>
date Thu, 08 Jul 2021 21:52:47 +0300
parents d8d48c977b0f
children e29c1ede905f
comparison
equal deleted inserted replaced
8837:8f0f6407ae23 8838:d6e191a583cc
205 205
206 206
207 static void 207 static void
208 ngx_http_v3_process_request(ngx_event_t *rev) 208 ngx_http_v3_process_request(ngx_event_t *rev)
209 { 209 {
210 u_char *p;
210 ssize_t n; 211 ssize_t n;
211 ngx_buf_t *b; 212 ngx_buf_t *b;
212 ngx_int_t rc; 213 ngx_int_t rc;
213 ngx_connection_t *c; 214 ngx_connection_t *c;
214 ngx_http_request_t *r; 215 ngx_http_request_t *r;
271 272
272 b->pos = b->start; 273 b->pos = b->start;
273 b->last = b->start + n; 274 b->last = b->start + n;
274 } 275 }
275 276
276 rc = ngx_http_v3_parse_headers(c, st, *b->pos); 277 p = b->pos;
278
279 rc = ngx_http_v3_parse_headers(c, st, b);
277 280
278 if (rc > 0) { 281 if (rc > 0) {
279 ngx_http_v3_finalize_connection(c, rc, 282 ngx_http_v3_finalize_connection(c, rc,
280 "could not parse request headers"); 283 "could not parse request headers");
281 ngx_http_finalize_request(r, NGX_HTTP_BAD_REQUEST); 284 ngx_http_finalize_request(r, NGX_HTTP_BAD_REQUEST);
300 } 303 }
301 304
302 break; 305 break;
303 } 306 }
304 307
305 b->pos++; 308 r->request_length += b->pos - p;
306 r->request_length++;
307 309
308 if (rc == NGX_AGAIN) { 310 if (rc == NGX_AGAIN) {
309 continue; 311 continue;
310 } 312 }
311 313
1022 static ngx_int_t 1024 static ngx_int_t
1023 ngx_http_v3_request_body_filter(ngx_http_request_t *r, ngx_chain_t *in) 1025 ngx_http_v3_request_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
1024 { 1026 {
1025 off_t max; 1027 off_t max;
1026 size_t size; 1028 size_t size;
1029 u_char *p;
1027 ngx_int_t rc; 1030 ngx_int_t rc;
1028 ngx_buf_t *b; 1031 ngx_buf_t *b;
1029 ngx_uint_t last; 1032 ngx_uint_t last;
1030 ngx_chain_t *cl, *out, *tl, **ll; 1033 ngx_chain_t *cl, *out, *tl, **ll;
1031 ngx_http_request_body_t *rb; 1034 ngx_http_request_body_t *rb;
1076 b = NULL; 1079 b = NULL;
1077 1080
1078 while (cl->buf->pos < cl->buf->last) { 1081 while (cl->buf->pos < cl->buf->last) {
1079 1082
1080 if (st->length == 0) { 1083 if (st->length == 0) {
1081 r->request_length++; 1084 p = cl->buf->pos;
1082 1085
1083 rc = ngx_http_v3_parse_data(r->connection, st, *cl->buf->pos++); 1086 rc = ngx_http_v3_parse_data(r->connection, st, cl->buf);
1087
1088 r->request_length += cl->buf->pos - p;
1084 1089
1085 if (rc == NGX_AGAIN) { 1090 if (rc == NGX_AGAIN) {
1086 continue; 1091 continue;
1087 } 1092 }
1088 1093