]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: connection: realign empty buffers in muxes, not transport layers
authorWilly Tarreau <w@1wt.eu>
Fri, 14 Dec 2018 09:51:23 +0000 (10:51 +0100)
committerWilly Tarreau <w@1wt.eu>
Fri, 14 Dec 2018 09:51:23 +0000 (10:51 +0100)
For a long time we've been realigning empty buffers in the transport
layers, where the I/Os were performed based on callbacks. Doing so is
optimal for higher data throughput but makes it trickier to optimize
unaligned data, where mux_h1/h2 have to claim some data are present
in the buffer to force unaligned accesses to skip the frame's header
or the chunk header.

We don't need to do this anymore since the I/O calls are now always
performed from top to bottom, so it's only the mux's responsibility
to realign an empty buffer if it wants to.

In practice it doesn't change anything, it's just a convention, and
it will allow the code to be simplified in a next patch.

src/mux_h1.c
src/mux_h2.c
src/mux_pt.c
src/raw_sock.c
src/ssl_sock.c

index bd7d0383533c0f200137caa97599fa73a4f359c8..7031d533fb6a6a1f61072daaf9da21acfba3fcd3 100644 (file)
@@ -1667,6 +1667,7 @@ static int h1_recv(struct h1c *h1c)
                int aligned = 0;
                h1c->flags &= ~H1C_F_IN_FULL;
 
+               b_realign_if_empty(&h1c->ibuf);
                if (!b_data(&h1c->ibuf)) {
                        /* try to pre-align the buffer like the rxbufs will be
                         * to optimize memory copies.
index 807f3197dda5005bc06a565e12e0884af8a8d3cc..2e3753d7c974a6e72a4922aa40487a2d4975a902 100644 (file)
@@ -2446,6 +2446,7 @@ static int h2_recv(struct h2c *h2c)
        do {
                int aligned = 0;
 
+               b_realign_if_empty(buf);
                if (!b_data(buf) && (h2c->proxy->options2 & PR_O2_USE_HTX)) {
                        /* HTX in use : try to pre-align the buffer like the
                         * rxbufs will be to optimize memory copies. We'll make
index 94824193a1ea74a7d2dfcfa895f5c803fa8f9b11..af69676314bb217740b8be2a638ac505dc2f2d2c 100644 (file)
@@ -249,6 +249,7 @@ static size_t mux_pt_rcv_buf(struct conn_stream *cs, struct buffer *buf, size_t
                cs->flags |= CS_FL_RCV_MORE;
                return 0;
        }
+       b_realign_if_empty(buf);
        ret = cs->conn->xprt->rcv_buf(cs->conn, buf, count, flags);
        if (conn_xprt_read0_pending(cs->conn)) {
                if (ret == 0)
index df861f48d59f9c7689b213763ec2bf81fd68039b..bdbcdede0242b1c6af72e50cc27f9fad374b6a5c 100644 (file)
@@ -276,8 +276,6 @@ static size_t raw_sock_to_buf(struct connection *conn, struct buffer *buf, size_
                }
        }
 
-       b_realign_if_empty(buf);
-
        /* read the largest possible block. For this, we perform only one call
         * to recv() unless the buffer wraps and we exactly fill the first hunk,
         * in which case we accept to do it once again. A new attempt is made on
index 5fd4f4e9e3e73a5e7cf7b7f20d1960d42afb369d..d722867da3e08a583cab8ea1319bb321b16b2bff 100644 (file)
@@ -5438,8 +5438,6 @@ static size_t ssl_sock_to_buf(struct connection *conn, struct buffer *buf, size_
                /* a handshake was requested */
                return 0;
 
-       b_realign_if_empty(buf);
-
        /* read the largest possible block. For this, we perform only one call
         * to recv() unless the buffer wraps and we exactly fill the first hunk,
         * in which case we accept to do it once again. A new attempt is made on