From 7cd492fe47813739811a1045d1addd2a91cbefe0 Mon Sep 17 00:00:00 2001 From: Shawn Silverman Date: Thu, 26 Sep 2019 18:00:27 -0700 Subject: [PATCH 1/2] A first go at implementing a fix for AsyncUDP's packet handling callback for both pass-as-reference and pass-as-copy versions. See https://github.com/espressif/arduino-esp32/issues/3287 and https://github.com/espressif/arduino-esp32/issues/3288. --- libraries/AsyncUDP/src/AsyncUDP.cpp | 19 +++++++++++++++++-- libraries/AsyncUDP/src/AsyncUDP.h | 1 + 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/libraries/AsyncUDP/src/AsyncUDP.cpp b/libraries/AsyncUDP/src/AsyncUDP.cpp index 762529b9e0f..b185a747223 100644 --- a/libraries/AsyncUDP/src/AsyncUDP.cpp +++ b/libraries/AsyncUDP/src/AsyncUDP.cpp @@ -324,6 +324,22 @@ AsyncUDPPacket::AsyncUDPPacket(AsyncUDP *udp, pbuf *pb, const ip_addr_t *raddr, } } +AsyncUDPPacket::AsyncUDPPacket(const AsyncUDPPacket &packet) + : _udp(packet._udp), + _pb(packet._pb), + _if(packet._if), + _localIp(packet._localIp), + _localPort(packet._localPort), + _remoteIp(packet._remoteIp), + _remotePort(packet.remotePort), + _data(packet._data), + _len(packet._len), + _index(packet._index) +{ + memcpy(_remoteMac, packet._remoteMac, sizeof(_remoteMac)); + pbuf_ref(_pb); +} + AsyncUDPPacket::~AsyncUDPPacket() { pbuf_free(_pb); @@ -682,9 +698,8 @@ void AsyncUDP::_recv(udp_pcb *upcb, pbuf *pb, const ip_addr_t *addr, uint16_t po if(_handler) { AsyncUDPPacket packet(this, this_pb, addr, port, netif); _handler(packet); - } else { - pbuf_free(this_pb); } + pbuf_free(this_pb); } } diff --git a/libraries/AsyncUDP/src/AsyncUDP.h b/libraries/AsyncUDP/src/AsyncUDP.h index 2ac48a69684..548b1527da2 100644 --- a/libraries/AsyncUDP/src/AsyncUDP.h +++ b/libraries/AsyncUDP/src/AsyncUDP.h @@ -59,6 +59,7 @@ class AsyncUDPPacket : public Stream size_t _index; public: AsyncUDPPacket(AsyncUDP *udp, pbuf *pb, const ip_addr_t *addr, uint16_t port, struct netif * netif); + AsyncUDPPacket(const AsyncUDPPacket &packet); virtual ~AsyncUDPPacket(); uint8_t * data(); From 46010edcde47257cbd1799c240d4a9aa55a86673 Mon Sep 17 00:00:00 2001 From: Shawn Silverman Date: Thu, 26 Sep 2019 18:51:41 -0700 Subject: [PATCH 2/2] Fixing the "_remotePort" missing '_'. --- libraries/AsyncUDP/src/AsyncUDP.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/AsyncUDP/src/AsyncUDP.cpp b/libraries/AsyncUDP/src/AsyncUDP.cpp index b185a747223..66d486c0231 100644 --- a/libraries/AsyncUDP/src/AsyncUDP.cpp +++ b/libraries/AsyncUDP/src/AsyncUDP.cpp @@ -331,7 +331,7 @@ AsyncUDPPacket::AsyncUDPPacket(const AsyncUDPPacket &packet) _localIp(packet._localIp), _localPort(packet._localPort), _remoteIp(packet._remoteIp), - _remotePort(packet.remotePort), + _remotePort(packet._remotePort), _data(packet._data), _len(packet._len), _index(packet._index)