comparison src/event/quic/ngx_event_quic.c @ 9050:aaca8e111959 quic

QUIC: post close event for connection close. Previously, close event was used only for close timeout, while read event was used for posting connection close.
author Roman Arutyunyan <arut@nginx.com>
date Wed, 07 Sep 2022 19:25:13 +0400
parents 2b4891fa0fbc
children 37d5dddabaea
comparison
equal deleted inserted replaced
9049:2b4891fa0fbc 9050:aaca8e111959
13 static ngx_quic_connection_t *ngx_quic_new_connection(ngx_connection_t *c, 13 static ngx_quic_connection_t *ngx_quic_new_connection(ngx_connection_t *c,
14 ngx_quic_conf_t *conf, ngx_quic_header_t *pkt); 14 ngx_quic_conf_t *conf, ngx_quic_header_t *pkt);
15 static ngx_int_t ngx_quic_handle_stateless_reset(ngx_connection_t *c, 15 static ngx_int_t ngx_quic_handle_stateless_reset(ngx_connection_t *c,
16 ngx_quic_header_t *pkt); 16 ngx_quic_header_t *pkt);
17 static void ngx_quic_input_handler(ngx_event_t *rev); 17 static void ngx_quic_input_handler(ngx_event_t *rev);
18 18 static void ngx_quic_close_handler(ngx_event_t *ev);
19 static void ngx_quic_close_timer_handler(ngx_event_t *ev);
20 19
21 static ngx_int_t ngx_quic_handle_datagram(ngx_connection_t *c, ngx_buf_t *b, 20 static ngx_int_t ngx_quic_handle_datagram(ngx_connection_t *c, ngx_buf_t *b,
22 ngx_quic_conf_t *conf); 21 ngx_quic_conf_t *conf);
23 static ngx_int_t ngx_quic_handle_packet(ngx_connection_t *c, 22 static ngx_int_t ngx_quic_handle_packet(ngx_connection_t *c,
24 ngx_quic_conf_t *conf, ngx_quic_header_t *pkt); 23 ngx_quic_conf_t *conf, ngx_quic_header_t *pkt);
281 qc->push.log = c->log; 280 qc->push.log = c->log;
282 qc->push.data = c; 281 qc->push.data = c;
283 qc->push.handler = ngx_quic_push_handler; 282 qc->push.handler = ngx_quic_push_handler;
284 qc->push.cancelable = 1; 283 qc->push.cancelable = 1;
285 284
285 qc->close.log = c->log;
286 qc->close.data = c;
287 qc->close.handler = ngx_quic_close_handler;
288 qc->close.cancelable = 1;
289
286 qc->path_validation.log = c->log; 290 qc->path_validation.log = c->log;
287 qc->path_validation.data = c; 291 qc->path_validation.data = c;
288 qc->path_validation.handler = ngx_quic_path_validation_handler; 292 qc->path_validation.handler = ngx_quic_path_validation_handler;
289 qc->path_validation.cancelable = 1; 293 qc->path_validation.cancelable = 1;
290 294
418 qc->error_reason = "graceful shutdown"; 422 qc->error_reason = "graceful shutdown";
419 ngx_quic_close_connection(c, NGX_OK); 423 ngx_quic_close_connection(c, NGX_OK);
420 return; 424 return;
421 } 425 }
422 426
423 if (!rev->ready) { 427 b = c->udp->buffer;
424 if (qc->closing) { 428 if (b == NULL) {
425 ngx_quic_close_connection(c, NGX_OK);
426
427 } else if (qc->shutdown) {
428 ngx_quic_shutdown_quic(c);
429 }
430
431 return; 429 return;
432 } 430 }
433
434 b = c->udp->buffer;
435 431
436 rc = ngx_quic_handle_datagram(c, b, NULL); 432 rc = ngx_quic_handle_datagram(c, b, NULL);
437 433
438 if (rc == NGX_ERROR) { 434 if (rc == NGX_ERROR) {
439 ngx_quic_close_connection(c, NGX_ERROR); 435 ngx_quic_close_connection(c, NGX_ERROR);
518 rc == NGX_ERROR ? 1 : 0, qc->draining, 514 rc == NGX_ERROR ? 1 : 0, qc->draining,
519 qc->error_app ? "app " : "", qc->error, 515 qc->error_app ? "app " : "", qc->error,
520 qc->error_reason ? qc->error_reason : ""); 516 qc->error_reason ? qc->error_reason : "");
521 517
522 if (rc == NGX_OK) { 518 if (rc == NGX_OK) {
523 qc->close.log = c->log;
524 qc->close.data = c;
525 qc->close.handler = ngx_quic_close_timer_handler;
526 qc->close.cancelable = 1;
527
528 ctx = ngx_quic_get_send_ctx(qc, qc->error_level); 519 ctx = ngx_quic_get_send_ctx(qc, qc->error_level);
529 ngx_add_timer(&qc->close, 3 * ngx_quic_pto(c, ctx)); 520 ngx_add_timer(&qc->close, 3 * ngx_quic_pto(c, ctx));
530 } 521 }
531 522
532 (void) ngx_quic_send_cc(c); 523 (void) ngx_quic_send_cc(c);
566 ngx_delete_posted_event(&qc->push); 557 ngx_delete_posted_event(&qc->push);
567 } 558 }
568 559
569 if (qc->close.timer_set) { 560 if (qc->close.timer_set) {
570 return; 561 return;
562 }
563
564 if (qc->close.posted) {
565 ngx_delete_posted_event(&qc->close);
571 } 566 }
572 567
573 ngx_quic_close_sockets(c); 568 ngx_quic_close_sockets(c);
574 569
575 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, c->log, 0, "quic close completed"); 570 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, c->log, 0, "quic close completed");
631 ngx_quic_shutdown_quic(c); 626 ngx_quic_shutdown_quic(c);
632 } 627 }
633 628
634 629
635 static void 630 static void
636 ngx_quic_close_timer_handler(ngx_event_t *ev) 631 ngx_quic_close_handler(ngx_event_t *ev)
637 { 632 {
638 ngx_connection_t *c; 633 ngx_connection_t *c;
639 634 ngx_quic_connection_t *qc;
640 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, ev->log, 0, "quic close timer"); 635
636 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, ev->log, 0, "quic close handler");
641 637
642 c = ev->data; 638 c = ev->data;
643 ngx_quic_close_connection(c, NGX_DONE); 639 qc = ngx_quic_get_connection(c);
640
641 if (qc->closing) {
642 ngx_quic_close_connection(c, NGX_OK);
643
644 } else if (qc->shutdown) {
645 ngx_quic_shutdown_quic(c);
646 }
644 } 647 }
645 648
646 649
647 static ngx_int_t 650 static ngx_int_t
648 ngx_quic_handle_datagram(ngx_connection_t *c, ngx_buf_t *b, 651 ngx_quic_handle_datagram(ngx_connection_t *c, ngx_buf_t *b,