Explorar o código

Fix bug #60681: Initialize custom data in pbuf struct

Add a #define that users can use to initialize LWIP_PBUF_CUSTOM_DATA fields.

see patch #10072
idea by Thomas Kindler <mail_lwip@t-kindler.de>
Thomas Kindler %!s(int64=4) %!d(string=hai) anos
pai
achega
de0b97861a
Modificáronse 2 ficheiros con 14 adicións e 0 borrados
  1. 2 0
      src/core/pbuf.c
  2. 12 0
      src/include/lwip/opt.h

+ 2 - 0
src/core/pbuf.c

@@ -186,6 +186,8 @@ pbuf_init_alloced_pbuf(struct pbuf *p, void *payload, u16_t tot_len, u16_t len,
   p->flags = flags;
   p->ref = 1;
   p->if_idx = NETIF_NO_INDEX;
+
+  LWIP_PBUF_CUSTOM_DATA_INIT(p);
 }
 
 /**

+ 12 - 0
src/include/lwip/opt.h

@@ -1628,10 +1628,22 @@
 /**
  * LWIP_PBUF_CUSTOM_DATA: Store private data on pbufs (e.g. timestamps)
  * This extends struct pbuf so user can store custom data on every pbuf.
+ * e.g.:
+ *  \#define LWIP_PBUF_CUSTOM_DATA   u32_t myref;
  */
 #if !defined LWIP_PBUF_CUSTOM_DATA || defined __DOXYGEN__
 #define LWIP_PBUF_CUSTOM_DATA
 #endif
+
+/**
+ * LWIP_PBUF_CUSTOM_DATA_INIT: Initialize private data on pbufs.
+ * e.g. for the above example definition:
+ *  \#define LWIP_PBUF_CUSTOM_DATA(p) (p)->myref = 0
+ */
+#if !defined LWIP_PBUF_CUSTOM_DATA_INIT || defined __DOXYGEN__
+#define LWIP_PBUF_CUSTOM_DATA_INIT(p)
+#endif
+
 /**
  * @}
  */