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().
This commit is contained in:
Frédéric Lécaille 2021-09-09 16:53:33 +02:00 committed by Amaury Denoyelle
parent b9c06fbe52
commit c7860007cc

View File

@ -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 <count> 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 <len> bytes from absolute position <src> of buffer <b> by <shift>
* 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