Skip to content

Commit 0d4b2ab

Browse files
authored
Merge pull request #18 from Rocketct/main
Managed packet list size to avoid memory fault due to messages overflow from the clients
2 parents 6674f81 + a68d706 commit 0d4b2ab

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

Diff for: src/Arduino_10BASE_T1S_UDP.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,12 @@ void Arduino_10BASE_T1S_UDP::onUdpRawRecv(struct udp_pcb *pcb, struct pbuf *p, c
235235
(uint8_t const *)p->payload,
236236
p->len);
237237

238-
_rx_pkt_list.push_back(rx_pkt);
238+
// drop the oldest packet if the list is full
239+
if(_rx_pkt_list.size() > _rx_pkt_list_size) {
240+
_rx_pkt_list.pop_front();
241+
}
239242

243+
_rx_pkt_list.push_back(rx_pkt);
240244
/* Free pbuf */
241245
pbuf_free(p);
242246
}

Diff for: src/Arduino_10BASE_T1S_UDP.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ class Arduino_10BASE_T1S_UDP : public UDP
6666
* it's used for internal purposes only.
6767
*/
6868
void onUdpRawRecv(struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *addr, uint16_t port);
69-
69+
void bufferSize(int size) {
70+
_rx_pkt_list_size = size;
71+
}
7072

7173
private:
7274
/* LWIP */
@@ -76,7 +78,7 @@ class Arduino_10BASE_T1S_UDP : public UDP
7678
IPAddress _send_to_ip;
7779
uint16_t _send_to_port;
7880
std::vector<uint8_t> _tx_data;
79-
81+
int _rx_pkt_list_size = 10;
8082
/* UDP RECEPTION */
8183
class UdpRxPacket
8284
{

0 commit comments

Comments
 (0)