]> git.kaiwu.me - nginx.git/commitdiff
QUIC: return written size from ngx_quic_write_chain().
authorRoman Arutyunyan <arut@nginx.com>
Thu, 13 Jan 2022 08:34:42 +0000 (11:34 +0300)
committerRoman Arutyunyan <arut@nginx.com>
Thu, 13 Jan 2022 08:34:42 +0000 (11:34 +0300)
This allows to escape calculating it before calling the function.

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

index 89bd6d236224baa215d995760261318e43cb0e2d..55e58d329d05f4aaf22ddc50080b1106251fc5f9 100644 (file)
@@ -478,13 +478,17 @@ ngx_quic_copy_buf(ngx_connection_t *c, u_char *data, size_t len)
 
 ngx_chain_t *
 ngx_quic_write_chain(ngx_connection_t *c, ngx_chain_t **chain, ngx_chain_t *in,
-    off_t limit, off_t offset)
+    off_t limit, off_t offset, size_t *size)
 {
     off_t         n;
     u_char       *p;
     ngx_buf_t    *b;
     ngx_chain_t  *cl, *sl;
 
+    if (size) {
+        *size = 0;
+    }
+
     while (in && limit) {
         cl = *chain;
 
@@ -549,6 +553,10 @@ ngx_quic_write_chain(ngx_connection_t *c, ngx_chain_t **chain, ngx_chain_t *in,
             in->buf->pos += n;
             offset += n;
             limit -= n;
+
+            if (size) {
+                *size += n;
+            }
         }
 
         if (b->sync && p == b->last) {
index 45505601fd3b35ae07f9e64af3c3cd1d7f6f5482..b06575d4e0c4d8c912d154e689f1a14b75b27d51 100644 (file)
@@ -31,7 +31,7 @@ void ngx_quic_free_chain(ngx_connection_t *c, ngx_chain_t *in);
 ngx_chain_t *ngx_quic_read_chain(ngx_connection_t *c, ngx_chain_t **chain,
     off_t limit);
 ngx_chain_t *ngx_quic_write_chain(ngx_connection_t *c, ngx_chain_t **chain,
-    ngx_chain_t *in, off_t limit, off_t offset);
+    ngx_chain_t *in, off_t limit, off_t offset, size_t *size);
 
 #if (NGX_DEBUG)
 void ngx_quic_log_frame(ngx_log_t *log, ngx_quic_frame_t *f, ngx_uint_t tx);
index 5cf579cb1abc4a8c6b9fbc9ff2b523657ad5c2df..e5e3ffcab87e1d6e6cba6b9d8cb51c4ecdc52f99 100644 (file)
@@ -370,7 +370,7 @@ ngx_quic_handle_crypto_frame(ngx_connection_t *c, ngx_quic_header_t *pkt,
 
     if (f->offset > ctx->crypto_received) {
         if (ngx_quic_write_chain(c, &ctx->crypto, frame->data, f->length,
-                                 f->offset - ctx->crypto_received)
+                                 f->offset - ctx->crypto_received, NULL)
             == NGX_CHAIN_ERROR)
         {
             return NGX_ERROR;
index 6f6ab5f9ea525856da6bd16254518c79e5e75230..5863265a7df558727f99732198f51d2dde4f98a6 100644 (file)
@@ -824,9 +824,10 @@ ngx_quic_stream_send(ngx_connection_t *c, u_char *buf, size_t size)
 static ngx_chain_t *
 ngx_quic_stream_send_chain(ngx_connection_t *c, ngx_chain_t *in, off_t limit)
 {
-    off_t                   n, flow;
+    off_t                   flow;
+    size_t                  n;
     ngx_event_t            *wev;
-    ngx_chain_t            *out, *cl;
+    ngx_chain_t            *out;
     ngx_connection_t       *pc;
     ngx_quic_frame_t       *frame;
     ngx_quic_stream_t      *qs;
@@ -851,17 +852,7 @@ ngx_quic_stream_send_chain(ngx_connection_t *c, ngx_chain_t *in, off_t limit)
         limit = flow;
     }
 
-    n = 0;
-
-    for (cl = in; cl; cl = cl->next) {
-        n += cl->buf->last - cl->buf->pos;
-        if (n >= limit) {
-            n = limit;
-            break;
-        }
-    }
-
-    in = ngx_quic_write_chain(pc, &qs->out, in, limit, 0);
+    in = ngx_quic_write_chain(pc, &qs->out, in, limit, 0, &n);
     if (in == NGX_CHAIN_ERROR) {
         return NGX_CHAIN_ERROR;
     }
@@ -1099,7 +1090,7 @@ ngx_quic_handle_stream_frame(ngx_connection_t *c, ngx_quic_header_t *pkt,
     }
 
     if (ngx_quic_write_chain(c, &qs->in, frame->data, f->length,
-                             f->offset - qs->recv_offset)
+                             f->offset - qs->recv_offset, NULL)
         == NGX_CHAIN_ERROR)
     {
         return NGX_ERROR;