Skip to content

Commit

Permalink
Managed packet list size to avoid memory fault due to messages overfl…
Browse files Browse the repository at this point in the history
…ow from the clients
  • Loading branch information
Rocketct committed Nov 13, 2024
1 parent 6674f81 commit a68d706
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/Arduino_10BASE_T1S_UDP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,12 @@ void Arduino_10BASE_T1S_UDP::onUdpRawRecv(struct udp_pcb *pcb, struct pbuf *p, c
(uint8_t const *)p->payload,
p->len);

_rx_pkt_list.push_back(rx_pkt);
// drop the oldest packet if the list is full
if(_rx_pkt_list.size() > _rx_pkt_list_size) {
_rx_pkt_list.pop_front();
}

_rx_pkt_list.push_back(rx_pkt);
/* Free pbuf */
pbuf_free(p);
}
Expand Down
6 changes: 4 additions & 2 deletions src/Arduino_10BASE_T1S_UDP.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ class Arduino_10BASE_T1S_UDP : public UDP
* it's used for internal purposes only.
*/
void onUdpRawRecv(struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *addr, uint16_t port);

void bufferSize(int size) {
_rx_pkt_list_size = size;
}

private:
/* LWIP */
Expand All @@ -76,7 +78,7 @@ class Arduino_10BASE_T1S_UDP : public UDP
IPAddress _send_to_ip;
uint16_t _send_to_port;
std::vector<uint8_t> _tx_data;

int _rx_pkt_list_size = 10;
/* UDP RECEPTION */
class UdpRxPacket
{
Expand Down

0 comments on commit a68d706

Please sign in to comment.