mirror of
https://github.com/nginx/nginx.git
synced 2025-06-25 07:50:40 +08:00
Refactored ngx_quic_close_connection().
The function is split into three: ngx_quic_close_connection() itself cleans up all core nginx things ngx_quic_close_quic() deals with everything inside c->quic ngx_quic_close_streams() deals with streams cleanup The quic and streams cleanup functions may return NGX_AGAIN, thus signalling that cleanup is not ready yet, and the close cannot continue to next step.
This commit is contained in:
parent
37b95d545c
commit
c8edca3137
@ -141,7 +141,11 @@ static ngx_int_t ngx_quic_new_connection(ngx_connection_t *c, ngx_ssl_t *ssl,
|
|||||||
ngx_connection_handler_pt handler);
|
ngx_connection_handler_pt handler);
|
||||||
static ngx_int_t ngx_quic_init_connection(ngx_connection_t *c);
|
static ngx_int_t ngx_quic_init_connection(ngx_connection_t *c);
|
||||||
static void ngx_quic_input_handler(ngx_event_t *rev);
|
static void ngx_quic_input_handler(ngx_event_t *rev);
|
||||||
|
|
||||||
static void ngx_quic_close_connection(ngx_connection_t *c);
|
static void ngx_quic_close_connection(ngx_connection_t *c);
|
||||||
|
static ngx_int_t ngx_quic_close_quic(ngx_connection_t *c);
|
||||||
|
static ngx_int_t ngx_quic_close_streams(ngx_connection_t *c,
|
||||||
|
ngx_quic_connection_t *qc);
|
||||||
|
|
||||||
static ngx_int_t ngx_quic_input(ngx_connection_t *c, ngx_buf_t *b);
|
static ngx_int_t ngx_quic_input(ngx_connection_t *c, ngx_buf_t *b);
|
||||||
static ngx_int_t ngx_quic_initial_input(ngx_connection_t *c,
|
static ngx_int_t ngx_quic_initial_input(ngx_connection_t *c,
|
||||||
@ -760,29 +764,87 @@ ngx_quic_input_handler(ngx_event_t *rev)
|
|||||||
static void
|
static void
|
||||||
ngx_quic_close_connection(ngx_connection_t *c)
|
ngx_quic_close_connection(ngx_connection_t *c)
|
||||||
{
|
{
|
||||||
#if (NGX_DEBUG)
|
|
||||||
ngx_uint_t ns;
|
|
||||||
#endif
|
|
||||||
ngx_uint_t i;
|
|
||||||
ngx_pool_t *pool;
|
ngx_pool_t *pool;
|
||||||
|
|
||||||
|
ngx_log_debug0(NGX_LOG_DEBUG_EVENT, c->log, 0, "close quic connection");
|
||||||
|
|
||||||
|
if (c->quic && ngx_quic_close_quic(c) == NGX_AGAIN) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (c->ssl) {
|
||||||
|
(void) ngx_ssl_shutdown(c);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (c->read->timer_set) {
|
||||||
|
ngx_del_timer(c->read);
|
||||||
|
}
|
||||||
|
|
||||||
|
#if (NGX_STAT_STUB)
|
||||||
|
(void) ngx_atomic_fetch_add(ngx_stat_active, -1);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
c->destroyed = 1;
|
||||||
|
|
||||||
|
pool = c->pool;
|
||||||
|
|
||||||
|
ngx_close_connection(c);
|
||||||
|
|
||||||
|
ngx_destroy_pool(pool);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static ngx_int_t
|
||||||
|
ngx_quic_close_quic(ngx_connection_t *c)
|
||||||
|
{
|
||||||
|
ngx_uint_t i;
|
||||||
|
ngx_quic_connection_t *qc;
|
||||||
|
|
||||||
|
qc = c->quic;
|
||||||
|
|
||||||
|
qc->closing = 1;
|
||||||
|
|
||||||
|
if (ngx_quic_close_streams(c, qc) == NGX_AGAIN) {
|
||||||
|
return NGX_AGAIN;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < NGX_QUIC_ENCRYPTION_LAST; i++) {
|
||||||
|
ngx_quic_free_frames(c, &qc->crypto[i].frames);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < NGX_QUIC_SEND_CTX_LAST; i++) {
|
||||||
|
ngx_quic_free_frames(c, &qc->send_ctx[i].frames);
|
||||||
|
ngx_quic_free_frames(c, &qc->send_ctx[i].sent);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (qc->push.timer_set) {
|
||||||
|
ngx_del_timer(&qc->push);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (qc->retry.timer_set) {
|
||||||
|
ngx_del_timer(&qc->retry);
|
||||||
|
}
|
||||||
|
|
||||||
|
return NGX_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static ngx_int_t
|
||||||
|
ngx_quic_close_streams(ngx_connection_t *c, ngx_quic_connection_t *qc)
|
||||||
|
{
|
||||||
ngx_event_t *rev;
|
ngx_event_t *rev;
|
||||||
ngx_rbtree_t *tree;
|
ngx_rbtree_t *tree;
|
||||||
ngx_rbtree_node_t *node;
|
ngx_rbtree_node_t *node;
|
||||||
ngx_quic_stream_t *qs;
|
ngx_quic_stream_t *qs;
|
||||||
ngx_quic_connection_t *qc;
|
|
||||||
|
|
||||||
ngx_log_debug0(NGX_LOG_DEBUG_EVENT, c->log, 0, "close quic connection");
|
#if (NGX_DEBUG)
|
||||||
|
ngx_uint_t ns;
|
||||||
|
#endif
|
||||||
|
|
||||||
qc = c->quic;
|
|
||||||
|
|
||||||
if (qc) {
|
|
||||||
|
|
||||||
qc->closing = 1;
|
|
||||||
tree = &qc->streams.tree;
|
tree = &qc->streams.tree;
|
||||||
|
|
||||||
if (tree->root != tree->sentinel) {
|
if (tree->root == tree->sentinel) {
|
||||||
if (c->read->timer_set) {
|
return NGX_OK;
|
||||||
ngx_del_timer(c->read);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if (NGX_DEBUG)
|
#if (NGX_DEBUG)
|
||||||
@ -813,42 +875,7 @@ ngx_quic_close_connection(ngx_connection_t *c)
|
|||||||
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0,
|
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0,
|
||||||
"quic connection has %ui active streams", ns);
|
"quic connection has %ui active streams", ns);
|
||||||
|
|
||||||
return;
|
return NGX_AGAIN;
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; i < NGX_QUIC_ENCRYPTION_LAST; i++) {
|
|
||||||
ngx_quic_free_frames(c, &qc->crypto[i].frames);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; i < NGX_QUIC_SEND_CTX_LAST; i++) {
|
|
||||||
ngx_quic_free_frames(c, &qc->send_ctx[i].frames);
|
|
||||||
ngx_quic_free_frames(c, &qc->send_ctx[i].sent);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (qc->push.timer_set) {
|
|
||||||
ngx_del_timer(&qc->push);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (qc->retry.timer_set) {
|
|
||||||
ngx_del_timer(&qc->retry);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (c->ssl) {
|
|
||||||
(void) ngx_ssl_shutdown(c);
|
|
||||||
}
|
|
||||||
|
|
||||||
#if (NGX_STAT_STUB)
|
|
||||||
(void) ngx_atomic_fetch_add(ngx_stat_active, -1);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
c->destroyed = 1;
|
|
||||||
|
|
||||||
pool = c->pool;
|
|
||||||
|
|
||||||
ngx_close_connection(c);
|
|
||||||
|
|
||||||
ngx_destroy_pool(pool);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user