]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: ring: add ring_dup() to copy a ring into another one
authorWilly Tarreau <w@1wt.eu>
Tue, 27 Feb 2024 18:52:00 +0000 (19:52 +0100)
committerWilly Tarreau <w@1wt.eu>
Mon, 25 Mar 2024 17:34:19 +0000 (17:34 +0000)
This will mostly be used during reallocation and boot-time duplicates,
the purpose is simply to save the caller from having to know the details
of the internal representation.

include/haproxy/ring.h

index b0add1d0c32fa712d0b750b33c335995243551e8..81440f538e2a82a53c581c8d121f0363d53be094 100644 (file)
@@ -57,6 +57,21 @@ static inline size_t ring_size(const struct ring *ring)
        return b_size(&ring->buf);
 }
 
+/* duplicates ring <src> over ring <dst> for no more than <max> bytes or no
+ * more than the amount of data present in <src>. It's assumed that the
+ * destination ring is always large enough for <max>. The number of bytes
+ * copied (the min of src's size and max) is returned.
+ */
+static inline size_t ring_dup(struct ring *dst, const struct ring *src, size_t max)
+{
+       if (max > ring_data(src))
+               max = ring_data(src);
+
+       b_reset(&dst->buf);
+       b_ncat(&dst->buf, &src->buf, max);
+       return max;
+}
+
 #endif /* _HAPROXY_RING_H */
 
 /*