diff src/event/quic/ngx_event_quic.c @ 8296:d710c457171c quic

QUIC: added ability to reset a stream.
author Sergey Kandaurov <pluknet@nginx.com>
date Wed, 17 Feb 2021 14:25:07 +0300
parents d4e02b3b734f
children 98bacfc65c61
line wrap: on
line diff
--- a/src/event/quic/ngx_event_quic.c
+++ b/src/event/quic/ngx_event_quic.c
@@ -2203,6 +2203,40 @@ ngx_quic_close_streams(ngx_connection_t 
 }
 
 
+ngx_int_t
+ngx_quic_reset_stream(ngx_connection_t *c, ngx_uint_t err)
+{
+    ngx_event_t            *wev;
+    ngx_connection_t       *pc;
+    ngx_quic_frame_t       *frame;
+    ngx_quic_stream_t      *qs;
+    ngx_quic_connection_t  *qc;
+
+    qs = c->quic;
+    pc = qs->parent;
+    qc = ngx_quic_get_connection(pc);
+
+    frame = ngx_quic_alloc_frame(pc);
+    if (frame == NULL) {
+        return NGX_ERROR;
+    }
+
+    frame->level = ssl_encryption_application;
+    frame->type = NGX_QUIC_FT_RESET_STREAM;
+    frame->u.reset_stream.id = qs->id;
+    frame->u.reset_stream.error_code = err;
+    frame->u.reset_stream.final_size = c->sent;
+
+    ngx_quic_queue_frame(qc, frame);
+
+    wev = c->write;
+    wev->error = 1;
+    wev->ready = 1;
+
+    return NGX_OK;
+}
+
+
 static ngx_int_t
 ngx_quic_input(ngx_connection_t *c, ngx_buf_t *b, ngx_quic_conf_t *conf)
 {
@@ -6408,6 +6442,10 @@ ngx_quic_stream_cleanup_handler(void *da
         }
     }
 
+    if (c->write->error) {
+        goto error;
+    }
+
     ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0,
                    "quic stream id:0x%xL send fin", qs->id);
 
@@ -6429,6 +6467,8 @@ ngx_quic_stream_cleanup_handler(void *da
 
     ngx_quic_queue_frame(qc, frame);
 
+error:
+
     (void) ngx_quic_output(pc);
 }