In order to support multiple TLVs per message, a list is needed.
This patch adds the list to the message structure.  This list will
eventually replace the 'last_tlv' field.

Signed-off-by: Richard Cochran <richardcoch...@gmail.com>
---
 msg.c | 16 ++++++++++++----
 msg.h |  5 +++++
 2 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/msg.c b/msg.c
index 52a59e7..adab384 100644
--- a/msg.c
+++ b/msg.c
@@ -204,6 +204,7 @@ struct ptp_message *msg_allocate(void)
        if (m) {
                memset(m, 0, sizeof(*m));
                m->refcnt = 1;
+               TAILQ_INIT(&m->tlv_list);
        }
 
        return m;
@@ -447,12 +448,19 @@ void msg_print(struct ptp_message *m, FILE *fp)
 
 void msg_put(struct ptp_message *m)
 {
+       struct tlv_extra *extra;
+
        m->refcnt--;
-       if (!m->refcnt) {
-               pool_stats.count++;
-               pool_debug("recycle", m);
-               TAILQ_INSERT_HEAD(&msg_pool, m, list);
+       if (m->refcnt) {
+               return;
+       }
+       pool_stats.count++;
+       pool_debug("recycle", m);
+       while ((extra = TAILQ_FIRST(&m->tlv_list)) != NULL) {
+               TAILQ_REMOVE(&m->tlv_list, extra, list);
+               tlv_extra_recycle(extra);
        }
+       TAILQ_INSERT_HEAD(&msg_pool, m, list);
 }
 
 int msg_sots_missing(struct ptp_message *m)
diff --git a/msg.h b/msg.h
index 12e6ce8..3d67c23 100644
--- a/msg.h
+++ b/msg.h
@@ -220,6 +220,11 @@ struct ptp_message {
         */
        struct address address;
        /**
+        * List of TLV descriptors.  Each item in the list contains
+        * pointers to the appended TLVs.
+        */
+       TAILQ_HEAD(tlv_list, tlv_extra) tlv_list;
+       /**
         * Contains the number of TLVs in the suffix.
         */
        int tlv_count;
-- 
2.11.0


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel

Reply via email to