mirror of
http://git.haproxy.org/git/haproxy.git/
synced 2025-03-25 04:17:42 +00:00
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:
parent
b9c06fbe52
commit
c7860007cc
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user