comparison src/http/v3/ngx_http_v3_request.c @ 9059:b87a0dbc1150 quic

HTTP/3: implement keepalive for hq. Previously, keepalive timer was deleted in ngx_http_v3_wait_request_handler() and set in request cleanup handler. This worked for HTTP/3 connections, but not for hq connections. Now keepalive timer is deleted in ngx_http_v3_init_request_stream() and set in connection cleanup handler, which works both for HTTP/3 and hq.
author Roman Arutyunyan <arut@nginx.com>
date Tue, 25 Oct 2022 12:52:09 +0400
parents b0c2234aaa9f
children e3760b9b7c8e
comparison
equal deleted inserted replaced
9058:b0c2234aaa9f 9059:b87a0dbc1150
10 #include <ngx_http.h> 10 #include <ngx_http.h>
11 11
12 12
13 static void ngx_http_v3_init_request_stream(ngx_connection_t *c); 13 static void ngx_http_v3_init_request_stream(ngx_connection_t *c);
14 static void ngx_http_v3_wait_request_handler(ngx_event_t *rev); 14 static void ngx_http_v3_wait_request_handler(ngx_event_t *rev);
15 static void ngx_http_v3_cleanup_connection(void *data);
15 static void ngx_http_v3_cleanup_request(void *data); 16 static void ngx_http_v3_cleanup_request(void *data);
16 static void ngx_http_v3_process_request(ngx_event_t *rev); 17 static void ngx_http_v3_process_request(ngx_event_t *rev);
17 static ngx_int_t ngx_http_v3_process_header(ngx_http_request_t *r, 18 static ngx_int_t ngx_http_v3_process_header(ngx_http_request_t *r,
18 ngx_str_t *name, ngx_str_t *value); 19 ngx_str_t *name, ngx_str_t *value);
19 static ngx_int_t ngx_http_v3_validate_header(ngx_http_request_t *r, 20 static ngx_int_t ngx_http_v3_validate_header(ngx_http_request_t *r,
163 ngx_http_v3_init_request_stream(ngx_connection_t *c) 164 ngx_http_v3_init_request_stream(ngx_connection_t *c)
164 { 165 {
165 uint64_t n; 166 uint64_t n;
166 ngx_event_t *rev; 167 ngx_event_t *rev;
167 ngx_connection_t *pc; 168 ngx_connection_t *pc;
169 ngx_pool_cleanup_t *cln;
168 ngx_http_connection_t *hc; 170 ngx_http_connection_t *hc;
169 ngx_http_v3_session_t *h3c; 171 ngx_http_v3_session_t *h3c;
170 ngx_http_core_loc_conf_t *clcf; 172 ngx_http_core_loc_conf_t *clcf;
171 ngx_http_core_srv_conf_t *cscf; 173 ngx_http_core_srv_conf_t *cscf;
172 174
218 220
219 ngx_http_v3_shutdown_connection(c, NGX_HTTP_V3_ERR_NO_ERROR, 221 ngx_http_v3_shutdown_connection(c, NGX_HTTP_V3_ERR_NO_ERROR,
220 "reached maximum number of requests"); 222 "reached maximum number of requests");
221 } 223 }
222 224
225 cln = ngx_pool_cleanup_add(c->pool, 0);
226 if (cln == NULL) {
227 ngx_http_close_connection(c);
228 return;
229 }
230
231 cln->handler = ngx_http_v3_cleanup_connection;
232 cln->data = c;
233
234 h3c->nrequests++;
235
236 if (h3c->keepalive.timer_set) {
237 ngx_del_timer(&h3c->keepalive);
238 }
239
223 rev = c->read; 240 rev = c->read;
224 241
225 #if (NGX_HTTP_V3_HQ) 242 #if (NGX_HTTP_V3_HQ)
226 if (!h3c->hq) 243 if (!h3c->hq)
227 #endif 244 #endif
254 ssize_t n; 271 ssize_t n;
255 ngx_buf_t *b; 272 ngx_buf_t *b;
256 ngx_connection_t *c; 273 ngx_connection_t *c;
257 ngx_pool_cleanup_t *cln; 274 ngx_pool_cleanup_t *cln;
258 ngx_http_request_t *r; 275 ngx_http_request_t *r;
259 ngx_http_v3_session_t *h3c;
260 ngx_http_connection_t *hc; 276 ngx_http_connection_t *hc;
261 ngx_http_core_srv_conf_t *cscf; 277 ngx_http_core_srv_conf_t *cscf;
262 278
263 c = rev->data; 279 c = rev->data;
264 280
374 return; 390 return;
375 } 391 }
376 392
377 cln->handler = ngx_http_v3_cleanup_request; 393 cln->handler = ngx_http_v3_cleanup_request;
378 cln->data = r; 394 cln->data = r;
379
380 h3c = ngx_http_v3_get_session(c);
381 h3c->nrequests++;
382
383 if (h3c->keepalive.timer_set) {
384 ngx_del_timer(&h3c->keepalive);
385 }
386 395
387 rev->handler = ngx_http_v3_process_request; 396 rev->handler = ngx_http_v3_process_request;
388 ngx_http_v3_process_request(rev); 397 ngx_http_v3_process_request(rev);
389 } 398 }
390 399
416 } 425 }
417 } 426 }
418 427
419 428
420 static void 429 static void
421 ngx_http_v3_cleanup_request(void *data) 430 ngx_http_v3_cleanup_connection(void *data)
422 { 431 {
423 ngx_http_request_t *r = data; 432 ngx_connection_t *c = data;
424 433
425 ngx_connection_t *c;
426 ngx_http_v3_session_t *h3c; 434 ngx_http_v3_session_t *h3c;
427 ngx_http_core_loc_conf_t *clcf; 435 ngx_http_core_loc_conf_t *clcf;
428
429 c = r->connection;
430
431 if (!r->response_sent) {
432 c->error = 1;
433 }
434 436
435 h3c = ngx_http_v3_get_session(c); 437 h3c = ngx_http_v3_get_session(c);
436 438
437 if (--h3c->nrequests == 0) { 439 if (--h3c->nrequests == 0) {
438 clcf = ngx_http_v3_get_module_loc_conf(c, ngx_http_core_module); 440 clcf = ngx_http_v3_get_module_loc_conf(c, ngx_http_core_module);
439 ngx_add_timer(&h3c->keepalive, clcf->keepalive_timeout); 441 ngx_add_timer(&h3c->keepalive, clcf->keepalive_timeout);
442 }
443 }
444
445
446 static void
447 ngx_http_v3_cleanup_request(void *data)
448 {
449 ngx_http_request_t *r = data;
450
451 if (!r->response_sent) {
452 r->connection->error = 1;
440 } 453 }
441 } 454 }
442 455
443 456
444 static void 457 static void