ngx_uint_t error_ftype;
const char *error_reason;
+ ngx_uint_t shutdown_code;
+ const char *shutdown_reason;
+
unsigned error_app:1;
unsigned send_timer_set:1;
unsigned closing:1;
+ unsigned shutdown:1;
unsigned draining:1;
unsigned key_phase:1;
unsigned validated:1;
ngx_chain_t *in, off_t limit);
static size_t ngx_quic_max_stream_flow(ngx_connection_t *c);
static void ngx_quic_stream_cleanup_handler(void *data);
+static void ngx_quic_shutdown_quic(ngx_connection_t *c);
static ngx_quic_frame_t *ngx_quic_alloc_frame(ngx_connection_t *c);
static void ngx_quic_free_frame(ngx_connection_t *c, ngx_quic_frame_t *frame);
}
}
+ p = ngx_slprintf(p, last, "%s", qc->shutdown ? " shutdown" : "");
p = ngx_slprintf(p, last, "%s", qc->closing ? " closing" : "");
p = ngx_slprintf(p, last, "%s", qc->draining ? " draining" : "");
p = ngx_slprintf(p, last, "%s", qc->key_phase ? " kp" : "");
}
+void
+ngx_quic_shutdown_connection(ngx_connection_t *c, ngx_uint_t err,
+ const char *reason)
+{
+ ngx_quic_connection_t *qc;
+
+ qc = ngx_quic_get_connection(c);
+ qc->shutdown = 1;
+ qc->shutdown_code = err;
+ qc->shutdown_reason = reason;
+
+ ngx_quic_shutdown_quic(c);
+}
+
+
static void
ngx_quic_close_timer_handler(ngx_event_t *ev)
{
qc = ngx_quic_get_connection(c);
+ if (qc->shutdown) {
+ return NGX_QUIC_STREAM_GONE;
+ }
+
if (id & NGX_QUIC_STREAM_UNIDIRECTIONAL) {
if (id & NGX_QUIC_STREAM_SERVER_INITIATED) {
}
sn->c->listening->handler(sn->c);
+
+ if (qc->shutdown) {
+ return NGX_QUIC_STREAM_GONE;
+ }
}
return ngx_quic_create_stream(c, id, n);
if (!c->read->pending_eof && !c->read->error) {
frame = ngx_quic_alloc_frame(pc);
if (frame == NULL) {
- return;
+ goto done;
}
frame->level = ssl_encryption_application;
if ((qs->id & NGX_QUIC_STREAM_SERVER_INITIATED) == 0) {
frame = ngx_quic_alloc_frame(pc);
if (frame == NULL) {
- return;
+ goto done;
}
frame->level = ssl_encryption_application;
if (qs->id & NGX_QUIC_STREAM_UNIDIRECTIONAL) {
/* do not send fin for client unidirectional streams */
- return;
+ goto done;
}
}
if (c->write->error) {
- goto error;
+ goto done;
}
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0,
frame = ngx_quic_alloc_frame(pc);
if (frame == NULL) {
- return;
+ goto done;
}
frame->level = ssl_encryption_application;
ngx_quic_queue_frame(qc, frame);
-error:
+done:
(void) ngx_quic_output(pc);
+
+ if (qc->shutdown) {
+ ngx_quic_shutdown_quic(pc);
+ }
+}
+
+
+static void
+ngx_quic_shutdown_quic(ngx_connection_t *c)
+{
+ ngx_rbtree_t *tree;
+ ngx_rbtree_node_t *node;
+ ngx_quic_stream_t *qs;
+ ngx_quic_connection_t *qc;
+
+ qc = ngx_quic_get_connection(c);
+
+ if (qc->closing) {
+ return;
+ }
+
+ tree = &qc->streams.tree;
+
+ if (tree->root != tree->sentinel) {
+ for (node = ngx_rbtree_min(tree->root, tree->sentinel);
+ node;
+ node = ngx_rbtree_next(tree, node))
+ {
+ qs = (ngx_quic_stream_t *) node;
+
+ if (!qs->cancelable) {
+ return;
+ }
+ }
+ }
+
+ ngx_quic_finalize_connection(c, qc->shutdown_code, qc->shutdown_reason);
}
uint64_t send_max_data;
ngx_buf_t *b;
ngx_quic_frames_stream_t fs;
+ ngx_uint_t cancelable; /* unsigned cancelable:1; */
};
ngx_connection_t *ngx_quic_open_stream(ngx_connection_t *c, ngx_uint_t bidi);
void ngx_quic_finalize_connection(ngx_connection_t *c, ngx_uint_t err,
const char *reason);
+void ngx_quic_shutdown_connection(ngx_connection_t *c, ngx_uint_t err,
+ const char *reason);
ngx_int_t ngx_quic_reset_stream(ngx_connection_t *c, ngx_uint_t err);
uint32_t ngx_quic_version(ngx_connection_t *c);
ngx_int_t ngx_quic_get_packet_dcid(ngx_log_t *log, u_char *data, size_t len,