From b095252a232361469275c1fda665b6d00d529f6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20L=C3=A9caille?= Date: Fri, 16 Jul 2021 11:42:44 +0200 Subject: [PATCH] MINOR: Add function for TX packets reference counting Add two functions to encrement or decrement a referenc counter attached to TX packet structure (struct quic_tx_packet). The packet are freed when their counters reach the null value. --- include/haproxy/xprt_quic-t.h | 2 ++ include/haproxy/xprt_quic.h | 13 +++++++++++++ 2 files changed, 15 insertions(+) diff --git a/include/haproxy/xprt_quic-t.h b/include/haproxy/xprt_quic-t.h index b5e7cad53..b83c34e6e 100644 --- a/include/haproxy/xprt_quic-t.h +++ b/include/haproxy/xprt_quic-t.h @@ -482,6 +482,8 @@ struct quic_tx_packet { struct quic_pktns *pktns; /* Flags. */ unsigned int flags; + /* Reference counter */ + int refcnt; /* Next packet in the same datagram */ struct quic_tx_packet *next; }; diff --git a/include/haproxy/xprt_quic.h b/include/haproxy/xprt_quic.h index 92091778f..57a565bd1 100644 --- a/include/haproxy/xprt_quic.h +++ b/include/haproxy/xprt_quic.h @@ -1064,6 +1064,19 @@ static inline void free_quic_rx_packet(struct quic_rx_packet *pkt) quic_rx_packet_refdec(pkt); } +/* Increment the reference counter of */ +static inline void quic_tx_packet_refinc(struct quic_tx_packet *pkt) +{ + HA_ATOMIC_ADD(&pkt->refcnt, 1); +} + +/* Decrement the reference counter of */ +static inline void quic_tx_packet_refdec(struct quic_tx_packet *pkt) +{ + if (!HA_ATOMIC_SUB_FETCH(&pkt->refcnt, 1)) + pool_free(pool_head_quic_tx_packet, pkt); +} + ssize_t quic_lstnr_dgram_read(char *buf, size_t len, void *owner, struct sockaddr_storage *saddr); ssize_t quic_srv_dgram_read(char *buf, size_t len, void *owner,