]> git.kaiwu.me - nginx.git/commitdiff
HTTP/3: ngx_http_v3_get_session() macro.
authorRoman Arutyunyan <arut@nginx.com>
Fri, 30 Apr 2021 16:10:11 +0000 (19:10 +0300)
committerRoman Arutyunyan <arut@nginx.com>
Fri, 30 Apr 2021 16:10:11 +0000 (19:10 +0300)
It's used instead of accessing c->quic->parent->data directly.  Apart from being
simpler, it allows to change the way session is stored in the future by changing
the macro.

src/http/v3/ngx_http_v3.h
src/http/v3/ngx_http_v3_filter_module.c
src/http/v3/ngx_http_v3_request.c
src/http/v3/ngx_http_v3_streams.c
src/http/v3/ngx_http_v3_tables.c

index 45d1a3671b627006d2139a4a303c76c40a4c3fb0..9ee809fa1e94e596bb7766eb52f62c7c57e89b1c 100644 (file)
@@ -74,6 +74,9 @@
 #define NGX_HTTP_V3_ERR_DECODER_STREAM_ERROR       0x202
 
 
+#define ngx_http_v3_get_session(c)                                            \
+    ((ngx_http_v3_connection_t *) (c)->quic->parent->data)
+
 #define ngx_http_v3_get_module_loc_conf(c, module)                            \
     ngx_http_get_module_loc_conf(                                             \
            ((ngx_http_v3_connection_t *) c->quic->parent->data)->hc.conf_ctx, \
index 30e38fcfbfb68ae2fa978b1aca98303b4c7e7b2e..b8b439c2432f4843c1bab70d5c58c220142a01c0 100644 (file)
@@ -783,7 +783,7 @@ ngx_http_v3_push_resource(ngx_http_request_t *r, ngx_str_t *path,
     ngx_http_v3_connection_t  *h3c;
 
     c = r->connection;
-    h3c = c->quic->parent->data;
+    h3c = ngx_http_v3_get_session(c);
     h3scf = ngx_http_get_module_srv_conf(r, ngx_http_v3_module);
 
     ngx_log_debug5(NGX_LOG_DEBUG_HTTP, c->log, 0,
@@ -858,7 +858,7 @@ ngx_http_v3_create_push_request(ngx_http_request_t *pr, ngx_str_t *path,
         goto failed;
     }
 
-    h3c = c->quic->parent->data;
+    h3c = ngx_http_v3_get_session(c);
     ngx_memcpy(hc, h3c, sizeof(ngx_http_connection_t));
     c->data = hc;
 
index c459efef5c7c5a50db7b1f14432a12e78e4d50ed..23b827aed89a098fd0b1222b6f7c9ee03a64ddce 100644 (file)
@@ -81,7 +81,7 @@ ngx_http_v3_init(ngx_connection_t *c)
 
     clcf = ngx_http_get_module_loc_conf(hc->conf_ctx, ngx_http_core_module);
 
-    h3c = c->quic->parent->data;
+    h3c = ngx_http_v3_get_session(c);
 
     if (h3c->goaway) {
         ngx_quic_reset_stream(c, NGX_HTTP_V3_ERR_REQUEST_REJECTED);
@@ -188,7 +188,7 @@ ngx_http_v3_cleanup_request(void *data)
     ngx_http_core_loc_conf_t  *clcf;
     ngx_http_v3_connection_t  *h3c;
 
-    h3c = c->quic->parent->data;
+    h3c = ngx_http_v3_get_session(c);
 
     if (--h3c->nrequests == 0) {
         clcf = ngx_http_v3_get_module_loc_conf(c, ngx_http_core_module);
index b300dcc017946cd1d86015646f72904aad83e993..513738469ee9bd3e8735a7f07e5f41f0eb76d777 100644 (file)
@@ -148,7 +148,7 @@ ngx_http_v3_close_uni_stream(ngx_connection_t *c)
     ngx_http_v3_uni_stream_t  *us;
 
     us = c->data;
-    h3c = c->quic->parent->data;
+    h3c = ngx_http_v3_get_session(c);
 
     ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http3 close stream");
 
@@ -178,7 +178,7 @@ ngx_http_v3_read_uni_stream_type(ngx_event_t *rev)
 
     c = rev->data;
     us = c->data;
-    h3c = c->quic->parent->data;
+    h3c = ngx_http_v3_get_session(c);
 
     ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http3 read stream type");
 
@@ -410,7 +410,7 @@ ngx_http_v3_create_push_stream(ngx_connection_t *c, uint64_t push_id)
         goto failed;
     }
 
-    h3c = c->quic->parent->data;
+    h3c = ngx_http_v3_get_session(c);
     h3c->npushing++;
 
     cln->handler = ngx_http_v3_push_cleanup;
@@ -466,7 +466,7 @@ ngx_http_v3_get_uni_stream(ngx_connection_t *c, ngx_uint_t type)
         index = -1;
     }
 
-    h3c = c->quic->parent->data;
+    h3c = ngx_http_v3_get_session(c);
 
     if (index >= 0) {
         if (h3c->known_streams[index]) {
@@ -525,7 +525,7 @@ ngx_http_v3_send_settings(ngx_connection_t *c)
     ngx_http_v3_srv_conf_t    *h3scf;
     ngx_http_v3_connection_t  *h3c;
 
-    h3c = c->quic->parent->data;
+    h3c = ngx_http_v3_get_session(c);
 
     ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http3 send settings");
 
@@ -837,7 +837,7 @@ ngx_http_v3_set_max_push_id(ngx_connection_t *c, uint64_t max_push_id)
 {
     ngx_http_v3_connection_t  *h3c;
 
-    h3c = c->quic->parent->data;
+    h3c = ngx_http_v3_get_session(c);
 
     ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0,
                    "http3 MAX_PUSH_ID:%uL", max_push_id);
@@ -860,7 +860,7 @@ ngx_http_v3_cancel_push(ngx_connection_t *c, uint64_t push_id)
     ngx_http_v3_push_t        *push;
     ngx_http_v3_connection_t  *h3c;
 
-    h3c = c->quic->parent->data;
+    h3c = ngx_http_v3_get_session(c);
 
     ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0,
                    "http3 CANCEL_PUSH:%uL", push_id);
index 1b4a73ab0fddbe5194e202f0dd0700daf3fb9a3b..c2ce1466008ce7c5c187002c66f560013d03fba8 100644 (file)
@@ -198,7 +198,7 @@ ngx_http_v3_insert(ngx_connection_t *c, ngx_str_t *name, ngx_str_t *value)
         return NGX_HTTP_V3_ERR_ENCODER_STREAM_ERROR;
     }
 
-    h3c = c->quic->parent->data;
+    h3c = ngx_http_v3_get_session(c);
     dt = &h3c->table;
 
     ngx_log_debug4(NGX_LOG_DEBUG_HTTP, c->log, 0,
@@ -250,8 +250,7 @@ ngx_http_v3_set_capacity(ngx_connection_t *c, ngx_uint_t capacity)
     ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0,
                    "http3 set capacity %ui", capacity);
 
-    pc = c->quic->parent;
-    h3c = pc->data;
+    h3c = ngx_http_v3_get_session(c);
     h3scf = ngx_http_get_module_srv_conf(h3c->hc.conf_ctx, ngx_http_v3_module);
 
     if (capacity > h3scf->max_table_capacity) {
@@ -278,6 +277,8 @@ ngx_http_v3_set_capacity(ngx_connection_t *c, ngx_uint_t capacity)
         }
 
         if (dt->elts == NULL) {
+            pc = c->quic->parent;
+
             cln = ngx_pool_cleanup_add(pc->pool, 0);
             if (cln == NULL) {
                 return NGX_ERROR;
@@ -324,7 +325,7 @@ ngx_http_v3_evict(ngx_connection_t *c, size_t need)
     ngx_http_v3_connection_t     *h3c;
     ngx_http_v3_dynamic_table_t  *dt;
 
-    h3c = c->quic->parent->data;
+    h3c = ngx_http_v3_get_session(c);
     dt = &h3c->table;
 
     if (need > dt->capacity) {
@@ -367,7 +368,7 @@ ngx_http_v3_duplicate(ngx_connection_t *c, ngx_uint_t index)
 
     ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, "http3 duplicate %ui", index);
 
-    h3c = c->quic->parent->data;
+    h3c = ngx_http_v3_get_session(c);
     dt = &h3c->table;
 
     if (dt->base + dt->nelts <= index) {
@@ -451,7 +452,7 @@ ngx_http_v3_lookup(ngx_connection_t *c, ngx_uint_t index, ngx_str_t *name,
     ngx_http_v3_connection_t     *h3c;
     ngx_http_v3_dynamic_table_t  *dt;
 
-    h3c = c->quic->parent->data;
+    h3c = ngx_http_v3_get_session(c);
     dt = &h3c->table;
 
     if (index < dt->base || index - dt->base >= dt->nelts) {
@@ -494,7 +495,7 @@ ngx_http_v3_decode_insert_count(ngx_connection_t *c, ngx_uint_t *insert_count)
         return NGX_OK;
     }
 
-    h3c = c->quic->parent->data;
+    h3c = ngx_http_v3_get_session(c);
     dt = &h3c->table;
 
     h3scf = ngx_http_get_module_srv_conf(h3c->hc.conf_ctx, ngx_http_v3_module);
@@ -536,15 +537,13 @@ ngx_int_t
 ngx_http_v3_check_insert_count(ngx_connection_t *c, ngx_uint_t insert_count)
 {
     size_t                        n;
-    ngx_connection_t             *pc;
     ngx_pool_cleanup_t           *cln;
     ngx_http_v3_block_t          *block;
     ngx_http_v3_srv_conf_t       *h3scf;
     ngx_http_v3_connection_t     *h3c;
     ngx_http_v3_dynamic_table_t  *dt;
 
-    pc = c->quic->parent;
-    h3c = pc->data;
+    h3c = ngx_http_v3_get_session(c);
     dt = &h3c->table;
 
     n = dt->base + dt->nelts;
@@ -624,7 +623,7 @@ ngx_http_v3_new_header(ngx_connection_t *c)
     ngx_http_v3_block_t       *block;
     ngx_http_v3_connection_t  *h3c;
 
-    h3c = c->quic->parent->data;
+    h3c = ngx_http_v3_get_session(c);
 
     ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0,
                    "http3 new dynamic header, blocked:%ui", h3c->nblocked);