@@ -34,6 +34,7 @@ void esp_schedule();
3434
3535#define PBUF_ALIGNER_ADJUST 4
3636#define PBUF_ALIGNER (x ) ((void *)((((intptr_t )(x))+3 )&~3 ))
37+ #define PBUF_HELPER_FLAG 0xff // lwIP pbuf flag: u8_t
3738
3839class UdpContext
3940{
@@ -243,21 +244,24 @@ class UdpContext
243244
244245 if (_rx_buf)
245246 {
246- // we have interleaved informations on addresses within reception pbuf chain:
247- // before: (data-pbuf) -> (data-pbuf) -> (data-pbuf) -> ... in the receiving order
248- // now: (address-info-pbuf -> data-pbuf) -> (address-info-pbuf -> data-pbuf) -> ...
247+ if (_rx_buf->flags == PBUF_HELPER_FLAG)
248+ {
249+ // we have interleaved informations on addresses within reception pbuf chain:
250+ // before: (data-pbuf) -> (data-pbuf) -> (data-pbuf) -> ... in the receiving order
251+ // now: (address-info-pbuf -> data-pbuf) -> (address-info-pbuf -> data-pbuf) -> ...
249252
250- // so the first rx_buf contains an address helper,
251- // copy it to "current address"
252- auto helper = (AddrHelper*)PBUF_ALIGNER (_rx_buf->payload );
253- _currentAddr = *helper;
253+ // so the first rx_buf contains an address helper,
254+ // copy it to "current address"
255+ auto helper = (AddrHelper*)PBUF_ALIGNER (_rx_buf->payload );
256+ _currentAddr = *helper;
254257
255- // destroy the helper in the about-to-be-released pbuf
256- helper->~AddrHelper ();
258+ // destroy the helper in the about-to-be-released pbuf
259+ helper->~AddrHelper ();
257260
258- // forward in rx_buf list, next one is effective data
259- // current (not ref'ed) one will be pbuf_free'd with deleteme
260- _rx_buf = _rx_buf->next ;
261+ // forward in rx_buf list, next one is effective data
262+ // current (not ref'ed) one will be pbuf_free'd with deleteme
263+ _rx_buf = _rx_buf->next ;
264+ }
261265
262266 // this rx_buf is not nullptr by construction,
263267 // ref'ing it to prevent release from the below pbuf_free(deleteme)
@@ -471,6 +475,7 @@ class UdpContext
471475 }
472476 // construct in place
473477 new (PBUF_ALIGNER (pb_helper->payload )) AddrHelper (srcaddr, TEMPDSTADDR, srcport);
478+ pb->flags = PBUF_HELPER_FLAG; // mark helper pbuf
474479 // chain it
475480 pbuf_cat (_rx_buf, pb_helper);
476481
0 commit comments