]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: mux-h1: Consume channel's data in a loop in h1_snd_buf()
authorChristopher Faulet <cfaulet@haproxy.com>
Thu, 22 Nov 2018 09:58:42 +0000 (10:58 +0100)
committerWilly Tarreau <w@1wt.eu>
Sat, 1 Dec 2018 16:37:27 +0000 (17:37 +0100)
In h1_snd_buf(), the data sending is done synchronously, as much as possible. So
if some data remains in the channel's buffer, because there was not enougth
place in the output buffer, it may be good the retry after a send because some
space may have been released when sending. Most of time the output buffer is
empty and all channel's data are consumed the first time. And if no data are
sent, we don't retry to do more. So the loop is just here to optimize edge cases
without any cost for all others.

src/mux_h1.c

index 6c104f309ac2941d0c3668dc7808f8b1aeb246c4..b70afa7ae6737a297171ef623f98d6cce6039a11 100644 (file)
@@ -1784,36 +1784,39 @@ static size_t h1_snd_buf(struct conn_stream *cs, struct buffer *buf, size_t coun
 {
        struct h1s *h1s = cs->ctx;
        struct h1c *h1c;
-       size_t ret = 0;
+       size_t total = 0;
 
        if (!h1s)
-               return ret;
+               return 0;
 
        h1c = h1s->h1c;
-
        if (h1c->flags & H1C_F_CS_WAIT_CONN)
                return 0;
 
-       if (!(h1c->flags & (H1C_F_OUT_FULL|H1C_F_OUT_ALLOC)))
-               ret = h1_process_output(h1c, buf, count);
-       if (ret > 0) {
-               h1_send(h1c);
+       while (total != count) {
+               size_t ret = 0;
 
-               /* We need to do that because of the infinite forwarding. <buf>
-                * contains HTX messages so when infinite forwarding is enabled,
-                * count is equal to the buffer size. From outside, the buffer
-                * appears as full.
-                */
-               if (!b_data(buf))
-                       ret = count;
+               if (!(h1c->flags & (H1C_F_OUT_FULL|H1C_F_OUT_ALLOC)))
+                       ret = h1_process_output(h1c, buf, count);
+               if (!ret)
+                       break;
+               total += ret;
+               if (!h1_send(h1c))
+                       break;
        }
 
-       if (count && ret != count) {
+       /* We need to do that because of the infinite forwarding. <buf>
+        * contains HTX messages so when infinite forwarding is enabled,
+        * count is equal to the buffer size. From outside, the buffer
+        * appears as full.
+        */
+       if (!b_data(buf))
+               total = count;
+       else if (total != count) {
                if (!(h1c->wait_event.wait_reason & SUB_CAN_SEND))
                        cs->conn->xprt->subscribe(cs->conn, SUB_CAN_SEND, &h1c->wait_event);
        }
-
-       return ret;
+       return total;
 }
 
 #if defined(CONFIG_HAP_LINUX_SPLICE)