]> git.kaiwu.me - nginx.git/commitdiff
QUIC: trim input chain in ngx_quic_buffer_write().
authorRoman Arutyunyan <arut@nginx.com>
Mon, 14 Feb 2022 11:51:10 +0000 (14:51 +0300)
committerRoman Arutyunyan <arut@nginx.com>
Mon, 14 Feb 2022 11:51:10 +0000 (14:51 +0300)
This allows to eliminate explicit trimming when handling input STREAM frame.
As a result, ngx_quic_trim_chain() is eliminated as well.

src/event/quic/ngx_event_quic_frames.c
src/event/quic/ngx_event_quic_frames.h
src/event/quic/ngx_event_quic_streams.c

index b89072ea2ed1042ed9cc4393a6214e9d05417110..4a39141ebbfb805e3d7088577bdcf956edb3efd5 100644 (file)
@@ -258,26 +258,6 @@ ngx_quic_free_frame(ngx_connection_t *c, ngx_quic_frame_t *frame)
 }
 
 
-void
-ngx_quic_trim_chain(ngx_chain_t *in, size_t size)
-{
-    size_t      n;
-    ngx_buf_t  *b;
-
-    while (in && size > 0) {
-        b = in->buf;
-        n = ngx_min((size_t) (b->last - b->pos), size);
-
-        b->pos += n;
-        size -= n;
-
-        if (b->pos == b->last) {
-            in = in->next;
-        }
-    }
-}
-
-
 void
 ngx_quic_free_chain(ngx_connection_t *c, ngx_chain_t *in)
 {
@@ -551,6 +531,22 @@ ngx_quic_write_buffer(ngx_connection_t *c, ngx_quic_buffer_t *qb,
     chain = &qb->chain;
 
     while (in && limit) {
+
+        if (offset < base) {
+            n = ngx_min((uint64_t) (in->buf->last - in->buf->pos),
+                        ngx_min(base - offset, limit));
+
+            in->buf->pos += n;
+            offset += n;
+            limit -= n;
+
+            if (in->buf->pos == in->buf->last) {
+                in = in->next;
+            }
+
+            continue;
+        }
+
         cl = *chain;
 
         if (cl == NULL) {
index 853e36ca16fe1fc46e9b82ba6ac41613d922a397..48cb22e917eba8220ec2f2bd43f6dcf9c1f4a4ef 100644 (file)
@@ -26,7 +26,6 @@ ngx_int_t ngx_quic_split_frame(ngx_connection_t *c, ngx_quic_frame_t *f,
 ngx_chain_t *ngx_quic_alloc_chain(ngx_connection_t *c);
 ngx_chain_t *ngx_quic_copy_buf(ngx_connection_t *c, u_char *data,
     size_t len);
-void ngx_quic_trim_chain(ngx_chain_t *in, size_t size);
 void ngx_quic_free_chain(ngx_connection_t *c, ngx_chain_t *in);
 
 ngx_chain_t *ngx_quic_read_buffer(ngx_connection_t *c, ngx_quic_buffer_t *qb,
index 1906bc69517a3814bf45e5388ddf3499c3bf335c..78650b04f0aca443b7330f0133ba4889b78c128f 100644 (file)
@@ -1115,11 +1115,6 @@ ngx_quic_handle_stream_frame(ngx_connection_t *c, ngx_quic_header_t *pkt,
         return NGX_OK;
     }
 
-    if (f->offset < qs->recv_offset) {
-        ngx_quic_trim_chain(frame->data, qs->recv_offset - f->offset);
-        f->offset = qs->recv_offset;
-    }
-
     if (f->fin) {
         if (qs->recv_final_size != (uint64_t) -1 && qs->recv_final_size != last)
         {