diff src/http/v3/ngx_http_v3_streams.c @ 8495:455a8536eaa7 quic

QUIC: limited the number of server-initiated streams. Also, ngx_quic_create_uni_stream() is replaced with ngx_quic_open_stream() which is capable of creating a bidi stream.
author Roman Arutyunyan <arut@nginx.com>
date Mon, 27 Jul 2020 18:51:42 +0300
parents 65c1fc5fae15
children 0596fe1aee16
line wrap: on
line diff
--- a/src/http/v3/ngx_http_v3_streams.c
+++ b/src/http/v3/ngx_http_v3_streams.c
@@ -55,16 +55,8 @@ ngx_http_v3_init_connection(ngx_connecti
         return NGX_OK;
     }
 
-    h3c = c->qs->parent->data;
-
-    if (!h3c->settings_sent) {
-        h3c->settings_sent = 1;
-
-        if (ngx_http_v3_send_settings(c) != NGX_OK) {
-            ngx_http_v3_finalize_connection(c, NGX_HTTP_V3_ERR_INTERNAL_ERROR,
-                                            "could not send settings");
-            return NGX_ERROR;
-        }
+    if (ngx_http_v3_send_settings(c) == NGX_ERROR) {
+        return NGX_ERROR;
     }
 
     if ((c->qs->id & NGX_QUIC_STREAM_UNIDIRECTIONAL) == 0) {
@@ -361,7 +353,7 @@ ngx_http_v3_get_uni_stream(ngx_connectio
         }
     }
 
-    sc = ngx_quic_create_uni_stream(c);
+    sc = ngx_quic_open_stream(c, 0);
     if (sc == NULL) {
         return NULL;
     }
@@ -410,14 +402,19 @@ ngx_http_v3_send_settings(ngx_connection
     ngx_http_v3_srv_conf_t    *h3scf;
     ngx_http_v3_connection_t  *h3c;
 
+    h3c = c->qs->parent->data;
+
+    if (h3c->settings_sent) {
+        return NGX_OK;
+    }
+
     ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http3 send settings");
 
     cc = ngx_http_v3_get_uni_stream(c, NGX_HTTP_V3_STREAM_CONTROL);
     if (cc == NULL) {
-        return NGX_ERROR;
+        return NGX_DECLINED;
     }
 
-    h3c = c->qs->parent->data;
     h3scf = ngx_http_get_module_srv_conf(h3c->hc.conf_ctx, ngx_http_v3_module);
 
     n = ngx_http_v3_encode_varlen_int(NULL,
@@ -441,12 +438,17 @@ ngx_http_v3_send_settings(ngx_connection
         goto failed;
     }
 
+    h3c->settings_sent = 1;
+
     return NGX_OK;
 
 failed:
 
     ngx_http_v3_close_uni_stream(cc);
 
+    ngx_http_v3_finalize_connection(c, NGX_HTTP_V3_ERR_INTERNAL_ERROR,
+                                    "could not send settings");
+
     return NGX_ERROR;
 }