[PATCH 03 of 10] QUIC: post close event for connection close
Roman Arutyunyan
arut at nginx.com
Thu Sep 8 09:06:30 UTC 2022
# HG changeset patch
# User Roman Arutyunyan <arut at nginx.com>
# Date 1662564313 -14400
# Wed Sep 07 19:25:13 2022 +0400
# Branch quic
# Node ID b4662fc66f1e8388f54d988777b741964892cec2
# Parent a3be42d42e7e6e6a941adb458cab201ff2cce8ce
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.
diff --git a/src/event/quic/ngx_event_quic.c b/src/event/quic/ngx_event_quic.c
--- a/src/event/quic/ngx_event_quic.c
+++ b/src/event/quic/ngx_event_quic.c
@@ -15,8 +15,7 @@ static ngx_quic_connection_t *ngx_quic_n
static ngx_int_t ngx_quic_handle_stateless_reset(ngx_connection_t *c,
ngx_quic_header_t *pkt);
static void ngx_quic_input_handler(ngx_event_t *rev);
-
-static void ngx_quic_close_timer_handler(ngx_event_t *ev);
+static void ngx_quic_close_handler(ngx_event_t *ev);
static ngx_int_t ngx_quic_handle_datagram(ngx_connection_t *c, ngx_buf_t *b,
ngx_quic_conf_t *conf);
@@ -283,6 +282,11 @@ ngx_quic_new_connection(ngx_connection_t
qc->push.handler = ngx_quic_push_handler;
qc->push.cancelable = 1;
+ qc->close.log = c->log;
+ qc->close.data = c;
+ qc->close.handler = ngx_quic_close_handler;
+ qc->close.cancelable = 1;
+
qc->path_validation.log = c->log;
qc->path_validation.data = c;
qc->path_validation.handler = ngx_quic_path_validation_handler;
@@ -420,19 +424,11 @@ ngx_quic_input_handler(ngx_event_t *rev)
return;
}
- if (!rev->ready) {
- if (qc->closing) {
- ngx_quic_close_connection(c, NGX_OK);
-
- } else if (qc->shutdown) {
- ngx_quic_shutdown_quic(c);
- }
-
+ b = c->udp->buffer;
+ if (b == NULL) {
return;
}
- b = c->udp->buffer;
-
rc = ngx_quic_handle_datagram(c, b, NULL);
if (rc == NGX_ERROR) {
@@ -520,11 +516,6 @@ ngx_quic_close_connection(ngx_connection
qc->error_reason ? qc->error_reason : "");
if (rc == NGX_OK) {
- qc->close.log = c->log;
- qc->close.data = c;
- qc->close.handler = ngx_quic_close_timer_handler;
- qc->close.cancelable = 1;
-
ctx = ngx_quic_get_send_ctx(qc, qc->error_level);
ngx_add_timer(&qc->close, 3 * ngx_quic_pto(c, ctx));
}
@@ -570,6 +561,10 @@ ngx_quic_close_connection(ngx_connection
return;
}
+ if (qc->close.posted) {
+ ngx_delete_posted_event(&qc->close);
+ }
+
ngx_quic_close_sockets(c);
ngx_log_debug0(NGX_LOG_DEBUG_EVENT, c->log, 0, "quic close completed");
@@ -633,14 +628,22 @@ ngx_quic_shutdown_connection(ngx_connect
static void
-ngx_quic_close_timer_handler(ngx_event_t *ev)
+ngx_quic_close_handler(ngx_event_t *ev)
{
- ngx_connection_t *c;
+ ngx_connection_t *c;
+ ngx_quic_connection_t *qc;
- ngx_log_debug0(NGX_LOG_DEBUG_EVENT, ev->log, 0, "quic close timer");
+ ngx_log_debug0(NGX_LOG_DEBUG_EVENT, ev->log, 0, "quic close handler");
c = ev->data;
- ngx_quic_close_connection(c, NGX_DONE);
+ qc = ngx_quic_get_connection(c);
+
+ if (qc->closing) {
+ ngx_quic_close_connection(c, NGX_OK);
+
+ } else if (qc->shutdown) {
+ ngx_quic_shutdown_quic(c);
+ }
}
diff --git a/src/event/quic/ngx_event_quic_streams.c b/src/event/quic/ngx_event_quic_streams.c
--- a/src/event/quic/ngx_event_quic_streams.c
+++ b/src/event/quic/ngx_event_quic_streams.c
@@ -1031,7 +1031,7 @@ ngx_quic_close_stream(ngx_quic_stream_t
if (qc->closing) {
/* schedule handler call to continue ngx_quic_close_connection() */
- ngx_post_event(pc->read, &ngx_posted_events);
+ ngx_post_event(&qc->close, &ngx_posted_events);
return NGX_OK;
}
@@ -1057,7 +1057,7 @@ ngx_quic_close_stream(ngx_quic_stream_t
}
if (qc->shutdown) {
- ngx_post_event(pc->read, &ngx_posted_events);
+ ngx_post_event(&qc->close, &ngx_posted_events);
}
return NGX_OK;
More information about the nginx-devel
mailing list