diff --git a/src/mux_h2.c b/src/mux_h2.c index eeaa0c1e0..806c817bd 100644 --- a/src/mux_h2.c +++ b/src/mux_h2.c @@ -2442,11 +2442,34 @@ static int h2_recv(struct h2c *h2c) } do { - max = buf->size - b_data(buf); + int aligned = 0; + + 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 + * sure that the frame header lands at the end of the + * HTX block to alias it upon recv. We cannot use the + * head because rcv_buf() will realign the buffer if + * it's empty. Thus we cheat and pretend we already + * have a few bytes there. + */ + max = buf_room_for_htx_data(buf) + 9; + buf->head = 0; + buf->data = sizeof(struct htx) - 9; + aligned = 1; + } + else + max = b_room(buf); + if (max) ret = conn->xprt->rcv_buf(conn, buf, max, 0); else ret = 0; + + if (aligned) { + buf->data -= sizeof(struct htx) - 9; + buf->head = sizeof(struct htx) - 9; + } } while (ret > 0); if (h2_recv_allowed(h2c) && (b_data(buf) < buf->size))