]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: mux-h2/htx: Support zero-copy when possible in h2_rcv_buf()
authorChristopher Faulet <cfaulet@haproxy.com>
Wed, 15 May 2019 08:07:59 +0000 (10:07 +0200)
committerWilly Tarreau <w@1wt.eu>
Tue, 28 May 2019 05:42:12 +0000 (07:42 +0200)
If the channel's buffer is empty and the message is small enough, we can swap
the H2S buffer with the channel one.

src/mux_h2.c

index 0a7c8ea060104c84688fc88cbaacff06ad3456e6..ddaa7518048d33af1ef289039ea32feb4de409b7 100644 (file)
@@ -5395,6 +5395,15 @@ static size_t h2_rcv_buf(struct conn_stream *cs, struct buffer *buf, size_t coun
                ret = h2s_htx->data;
                buf_htx = htx_from_buf(buf);
 
+               /* <buf> is empty and the message is small enough, swap the
+                * buffers. */
+               if (htx_is_empty(buf_htx) && htx_used_space(h2s_htx) <= count) {
+                       htx_to_buf(buf_htx, buf);
+                       htx_to_buf(h2s_htx, &h2s->rxbuf);
+                       b_xfer(buf, &h2s->rxbuf, b_data(&h2s->rxbuf));
+                       goto end;
+               }
+
                htx_xfer_blks(buf_htx, h2s_htx, count, HTX_BLK_EOM);
 
                if (h2s_htx->flags & HTX_FL_PARSING_ERROR)