Skip to content

Commit c2a63a1

Browse files
committed
fix
1 parent f6b1910 commit c2a63a1

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

libraries/AsyncUDP/src/AsyncUDP.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,33 @@ AsyncUDPPacket::AsyncUDPPacket(AsyncUDPPacket &packet) {
317317
pbuf_ref(_pb);
318318
}
319319

320+
AsyncUDPPacket& AsyncUDPPacket::operator=(const AsyncUDPPacket& packet) {
321+
if (this != &packet) {
322+
if (_pb) {
323+
// Free existing pbuf reference
324+
pbuf_free(_pb);
325+
}
326+
327+
// Copy all members
328+
_udp = packet._udp;
329+
_pb = packet._pb;
330+
_if = packet._if;
331+
_data = packet._data;
332+
_len = packet._len;
333+
_index = 0;
334+
335+
memcpy(&_remoteIp, &packet._remoteIp, sizeof(ip_addr_t));
336+
memcpy(&_localIp, &packet._localIp, sizeof(ip_addr_t));
337+
_localPort = packet._localPort;
338+
_remotePort = packet._remotePort;
339+
memcpy(_remoteMac, packet._remoteMac, 6);
340+
341+
// Increment reference count for the new pbuf
342+
pbuf_ref(_pb);
343+
}
344+
return *this;
345+
}
346+
320347
AsyncUDPPacket::AsyncUDPPacket(AsyncUDP *udp, pbuf *pb, const ip_addr_t *raddr, uint16_t rport, struct netif *ntif) {
321348
_udp = udp;
322349
_pb = pb;

libraries/AsyncUDP/src/AsyncUDP.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ class AsyncUDPPacket : public Stream {
100100

101101
size_t write(const uint8_t *data, size_t len);
102102
size_t write(uint8_t data);
103+
104+
// Copy assignment operator
105+
AsyncUDPPacket& operator=(const AsyncUDPPacket& packet);
103106
};
104107

105108
class AsyncUDP : public Print {

0 commit comments

Comments
 (0)