From 2f6edc84a8a62fd21c817f5e8b0483f30a205284 Mon Sep 17 00:00:00 2001 From: Christopher Faulet Date: Wed, 15 May 2019 10:07:59 +0200 Subject: [PATCH] MINOR: mux-h2/htx: Support zero-copy when possible in h2_rcv_buf() 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 | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/mux_h2.c b/src/mux_h2.c index 0a7c8ea06..ddaa75180 100644 --- a/src/mux_h2.c +++ b/src/mux_h2.c @@ -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); + /* 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)