Skip to content

Commit 7cd492f

Browse files
committed
A first go at implementing a fix for AsyncUDP's packet handling callback for both pass-as-reference and pass-as-copy versions. See espressif#3287 and espressif#3288.
1 parent 9bbd720 commit 7cd492f

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

libraries/AsyncUDP/src/AsyncUDP.cpp

+17-2
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,22 @@ AsyncUDPPacket::AsyncUDPPacket(AsyncUDP *udp, pbuf *pb, const ip_addr_t *raddr,
324324
}
325325
}
326326

327+
AsyncUDPPacket::AsyncUDPPacket(const AsyncUDPPacket &packet)
328+
: _udp(packet._udp),
329+
_pb(packet._pb),
330+
_if(packet._if),
331+
_localIp(packet._localIp),
332+
_localPort(packet._localPort),
333+
_remoteIp(packet._remoteIp),
334+
_remotePort(packet.remotePort),
335+
_data(packet._data),
336+
_len(packet._len),
337+
_index(packet._index)
338+
{
339+
memcpy(_remoteMac, packet._remoteMac, sizeof(_remoteMac));
340+
pbuf_ref(_pb);
341+
}
342+
327343
AsyncUDPPacket::~AsyncUDPPacket()
328344
{
329345
pbuf_free(_pb);
@@ -682,9 +698,8 @@ void AsyncUDP::_recv(udp_pcb *upcb, pbuf *pb, const ip_addr_t *addr, uint16_t po
682698
if(_handler) {
683699
AsyncUDPPacket packet(this, this_pb, addr, port, netif);
684700
_handler(packet);
685-
} else {
686-
pbuf_free(this_pb);
687701
}
702+
pbuf_free(this_pb);
688703
}
689704
}
690705

libraries/AsyncUDP/src/AsyncUDP.h

+1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ class AsyncUDPPacket : public Stream
5959
size_t _index;
6060
public:
6161
AsyncUDPPacket(AsyncUDP *udp, pbuf *pb, const ip_addr_t *addr, uint16_t port, struct netif * netif);
62+
AsyncUDPPacket(const AsyncUDPPacket &packet);
6263
virtual ~AsyncUDPPacket();
6364

6465
uint8_t * data();

0 commit comments

Comments
 (0)