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

Vladimir Homutov vl at nginx.com
Mon Jan 31 12:18:44 UTC 2022


On Mon, Jan 31, 2022 at 10:34:08AM +0300, Roman Arutyunyan wrote:
> # 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 9f5c59800a9894aad00b06df93ec454aab97372d
> # Parent  d3c6dea9454c48ded14b8c087dffc4dea46f78ef
> 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 *
> @@ -156,7 +157,6 @@ ngx_quic_close_streams(ngx_connection_t
>  {
>      ngx_pool_t         *pool;
>      ngx_queue_t        *q;
> -    ngx_event_t        *rev, *wev;
>      ngx_rbtree_t       *tree;
>      ngx_rbtree_node_t  *node;
>      ngx_quic_stream_t  *qs;
> @@ -195,17 +195,8 @@ ngx_quic_close_streams(ngx_connection_t
>          qs->recv_state = NGX_QUIC_STREAM_RECV_RESET_RECVD;
>          qs->send_state = NGX_QUIC_STREAM_SEND_RESET_SENT;
>
> -        rev = qs->connection->read;
> -        rev->ready = 1;
> -
> -        wev = qs->connection->write;
> -        wev->ready = 1;
> -
> -        ngx_post_event(rev, &ngx_posted_events);
> -
> -        if (rev->timer_set) {
> -            ngx_del_timer(rev);
> -        }
> +        ngx_quic_set_event(qs->connection->read);
> +        ngx_quic_set_event(qs->connection->write);
>
>  #if (NGX_DEBUG)
>          ns++;
> @@ -1024,7 +1015,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;
> @@ -1102,12 +1092,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;
> @@ -1118,7 +1103,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;
> @@ -1140,12 +1124,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);
>          }
>      }
>
> @@ -1206,7 +1185,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;
>
> @@ -1236,12 +1214,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;
> @@ -1254,7 +1227,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;
> @@ -1308,12 +1280,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;
>  }
> @@ -1323,7 +1290,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;
>
> @@ -1350,12 +1316,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;
>  }
> @@ -1394,7 +1355,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;
>
> @@ -1405,13 +1365,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;
> @@ -1585,6 +1543,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)
>  {


Looks ok_______________________________________________



More information about the nginx-devel mailing list