[PATCH 2 of 2] QUIC: stream event setting function

Roman Arutyunyan arut at nginx.com
Wed Jan 26 09:06:54 UTC 2022


# HG changeset patch
# User Roman Arutyunyan <arut at nginx.com>
# Date 1643187691 -10800
#      Wed Jan 26 12:01:31 2022 +0300
# Branch quic
# Node ID b019e99bc72b2fe0027af25c9cc1bf33c287eb22
# Parent  42776baa77bea8da4cc0e3a157f122f0803b1e97
QUIC: stream event setting function.

The function ngx_quic_set_event() is now called instead of posting events
directly.

diff --git a/src/event/quic/ngx_event_quic_streams.c b/src/event/quic/ngx_event_quic_streams.c
--- a/src/event/quic/ngx_event_quic_streams.c
+++ b/src/event/quic/ngx_event_quic_streams.c
@@ -34,6 +34,7 @@ static ngx_int_t ngx_quic_control_flow(n
 static ngx_int_t ngx_quic_update_flow(ngx_connection_t *c, uint64_t last);
 static ngx_int_t ngx_quic_update_max_stream_data(ngx_connection_t *c);
 static ngx_int_t ngx_quic_update_max_data(ngx_connection_t *c);
+static void ngx_quic_set_event(ngx_event_t *ev);
 
 
 ngx_connection_t *
@@ -1022,7 +1023,6 @@ ngx_quic_handle_stream_frame(ngx_connect
     ngx_quic_frame_t *frame)
 {
     uint64_t                  last;
-    ngx_event_t              *rev;
     ngx_connection_t         *sc;
     ngx_quic_stream_t        *qs;
     ngx_quic_connection_t    *qc;
@@ -1100,12 +1100,7 @@ ngx_quic_handle_stream_frame(ngx_connect
     }
 
     if (f->offset == qs->recv_offset) {
-        rev = sc->read;
-        rev->ready = 1;
-
-        if (rev->active) {
-            ngx_post_event(rev, &ngx_posted_events);
-        }
+        ngx_quic_set_event(sc->read);
     }
 
     return NGX_OK;
@@ -1116,7 +1111,6 @@ ngx_int_t
 ngx_quic_handle_max_data_frame(ngx_connection_t *c,
     ngx_quic_max_data_frame_t *f)
 {
-    ngx_event_t            *wev;
     ngx_rbtree_t           *tree;
     ngx_rbtree_node_t      *node;
     ngx_quic_stream_t      *qs;
@@ -1138,12 +1132,7 @@ ngx_quic_handle_max_data_frame(ngx_conne
              node = ngx_rbtree_next(tree, node))
         {
             qs = (ngx_quic_stream_t *) node;
-            wev = qs->connection->write;
-
-            if (wev->active) {
-                wev->ready = 1;
-                ngx_post_event(wev, &ngx_posted_events);
-            }
+            ngx_quic_set_event(qs->connection->write);
         }
     }
 
@@ -1204,7 +1193,6 @@ ngx_quic_handle_max_stream_data_frame(ng
     ngx_quic_header_t *pkt, ngx_quic_max_stream_data_frame_t *f)
 {
     uint64_t                sent;
-    ngx_event_t            *wev;
     ngx_quic_stream_t      *qs;
     ngx_quic_connection_t  *qc;
 
@@ -1234,12 +1222,7 @@ ngx_quic_handle_max_stream_data_frame(ng
     sent = qs->connection->sent;
 
     if (sent >= qs->send_max_data) {
-        wev = qs->connection->write;
-
-        if (wev->active) {
-            wev->ready = 1;
-            ngx_post_event(wev, &ngx_posted_events);
-        }
+        ngx_quic_set_event(qs->connection->write);
     }
 
     qs->send_max_data = f->limit;
@@ -1252,7 +1235,6 @@ ngx_int_t
 ngx_quic_handle_reset_stream_frame(ngx_connection_t *c,
     ngx_quic_header_t *pkt, ngx_quic_reset_stream_frame_t *f)
 {
-    ngx_event_t            *rev;
     ngx_connection_t       *sc;
     ngx_quic_stream_t      *qs;
     ngx_quic_connection_t  *qc;
@@ -1306,12 +1288,7 @@ ngx_quic_handle_reset_stream_frame(ngx_c
         return NGX_ERROR;
     }
 
-    rev = sc->read;
-    rev->ready = 1;
-
-    if (rev->active) {
-        ngx_post_event(rev, &ngx_posted_events);
-    }
+    ngx_quic_set_event(qs->connection->read);
 
     return NGX_OK;
 }
@@ -1321,7 +1298,6 @@ ngx_int_t
 ngx_quic_handle_stop_sending_frame(ngx_connection_t *c,
     ngx_quic_header_t *pkt, ngx_quic_stop_sending_frame_t *f)
 {
-    ngx_event_t            *wev;
     ngx_quic_stream_t      *qs;
     ngx_quic_connection_t  *qc;
 
@@ -1348,12 +1324,7 @@ ngx_quic_handle_stop_sending_frame(ngx_c
         return NGX_ERROR;
     }
 
-    wev = qs->connection->write;
-
-    if (wev->active) {
-        wev->ready = 1;
-        ngx_post_event(wev, &ngx_posted_events);
-    }
+    ngx_quic_set_event(qs->connection->write);
 
     return NGX_OK;
 }
@@ -1392,7 +1363,6 @@ void
 ngx_quic_handle_stream_ack(ngx_connection_t *c, ngx_quic_frame_t *f)
 {
     uint64_t                sent, unacked;
-    ngx_event_t            *wev;
     ngx_quic_stream_t      *qs;
     ngx_quic_connection_t  *qc;
 
@@ -1403,13 +1373,11 @@ ngx_quic_handle_stream_ack(ngx_connectio
         return;
     }
 
-    wev = qs->connection->write;
     sent = qs->connection->sent;
     unacked = sent - qs->acked;
 
-    if (unacked >= qc->conf->stream_buffer_size && wev->active) {
-        wev->ready = 1;
-        ngx_post_event(wev, &ngx_posted_events);
+    if (unacked >= qc->conf->stream_buffer_size) {
+        ngx_quic_set_event(qs->connection->write);
     }
 
     qs->acked += f->u.stream.length;
@@ -1581,6 +1549,17 @@ ngx_quic_update_max_data(ngx_connection_
 }
 
 
+static void
+ngx_quic_set_event(ngx_event_t *ev)
+{
+    ev->ready = 1;
+
+    if (ev->active) {
+        ngx_post_event(ev, &ngx_posted_events);
+    }
+}
+
+
 ngx_int_t
 ngx_quic_handle_read_event(ngx_event_t *rev, ngx_uint_t flags)
 {



More information about the nginx-devel mailing list