From: Frédéric Lécaille Date: Thu, 9 Sep 2021 14:53:33 +0000 (+0200) Subject: MINOR: buf: Add b_force_xfer() function X-Git-Tag: v2.5-dev8~43 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c7860007cc;p=thirdparty%2Fhaproxy.git MINOR: buf: Add b_force_xfer() function This function does exactly the same thing as b_xfer() which transfers data from a struct buffer to another one but without zero copy when the destination buffer is empty. This is at least useful to transfer h3 data to the QUIC mux from buffer with garbage medata which have been used to build h3 frames without too much memcopy()/memmove(). --- diff --git a/include/haproxy/buf.h b/include/haproxy/buf.h index f66f5c6870..20f260d195 100644 --- a/include/haproxy/buf.h +++ b/include/haproxy/buf.h @@ -587,6 +587,39 @@ static inline size_t b_xfer(struct buffer *dst, struct buffer *src, size_t count return ret; } +/* b_force_xfer() : same as b_xfer() but without zero copy. + * The caller is responsible for ensuring that is not + * larger than b_room(dst). + */ +static inline size_t b_force_xfer(struct buffer *dst, struct buffer *src, size_t count) +{ + size_t ret, block1, block2; + + ret = 0; + if (!count) + goto leave; + + ret = b_data(src); + if (!ret) + goto leave; + + if (ret > count) + ret = count; + block1 = b_contig_data(src, 0); + if (block1 > ret) + block1 = ret; + block2 = ret - block1; + + if (block1) + __b_putblk(dst, b_head(src), block1); + + if (block2) + __b_putblk(dst, b_peek(src, block1), block2); + + b_del(src, ret); + leave: + return ret; +} /* Moves bytes from absolute position of buffer by * bytes, while supporting wrapping of both the source and the destination. * The position is relative to the buffer's origin and may overlap with the