@@ -28,6 +28,7 @@ Arduino_10BASE_T1S_UDP::Arduino_10BASE_T1S_UDP()
2828: _udp_pcb{nullptr }
2929, _send_to_ip{0 ,0 ,0 ,0 }
3030, _send_to_port{0 }
31+ , _rx_pkt{nullptr }
3132{
3233
3334}
@@ -136,70 +137,83 @@ size_t Arduino_10BASE_T1S_UDP::write(const uint8_t * buffer, size_t size)
136137int Arduino_10BASE_T1S_UDP::parsePacket ()
137138{
138139 if (_rx_pkt_list.size ())
139- return _rx_pkt_list.front ()->totalSize ();
140+ {
141+ /* Discard UdpRxPacket object previously held by _rx_pkt
142+ * and replace it with the new one.
143+ */
144+ _rx_pkt = _rx_pkt_list.front ();
145+ _rx_pkt_list.pop_front ();
146+ return _rx_pkt->totalSize ();
147+ }
140148 else
149+ {
150+ /* Otherwise ensure that _rx_pkt definitely
151+ * does not hold any UdpRxPacket object anymore.
152+ */
153+ _rx_pkt.reset ();
141154 return 0 ;
155+ }
142156}
143157
144158int Arduino_10BASE_T1S_UDP::available ()
145159{
146- if (_rx_pkt_list. size () )
147- return _rx_pkt_list. front () ->available ();
160+ if (_rx_pkt )
161+ return _rx_pkt ->available ();
148162 else
149163 return 0 ;
150164}
151165
152166int Arduino_10BASE_T1S_UDP::read ()
153167{
154- if (_rx_pkt_list. size () )
155- return _rx_pkt_list. front () ->read ();
168+ if (_rx_pkt )
169+ return _rx_pkt ->read ();
156170 else
157171 return -1 ;
158172}
159173
160174int Arduino_10BASE_T1S_UDP::read (unsigned char * buffer, size_t len)
161175{
162- if (_rx_pkt_list. size () )
163- return _rx_pkt_list. front () ->read (buffer, len);
176+ if (_rx_pkt )
177+ return _rx_pkt ->read (buffer, len);
164178 else
165179 return -1 ;
166180}
167181
168182int Arduino_10BASE_T1S_UDP::read (char * buffer, size_t len)
169183{
170- if (_rx_pkt_list. size () )
171- return _rx_pkt_list. front () ->read (buffer, len);
184+ if (_rx_pkt )
185+ return _rx_pkt ->read (buffer, len);
172186 else
173187 return -1 ;
174188}
175189
176190int Arduino_10BASE_T1S_UDP::peek ()
177191{
178- if (_rx_pkt_list. size () )
179- return _rx_pkt_list. front () ->peek ();
192+ if (_rx_pkt )
193+ return _rx_pkt ->peek ();
180194 else
181195 return -1 ;
182196}
183197
184198void Arduino_10BASE_T1S_UDP::flush ()
185199{
186- /* Drop packet from receive buffer . */
187- if (_rx_pkt_list. size () )
188- _rx_pkt_list. pop_front ();
200+ /* Delete UdpRxPacket object held by _rx_pkt . */
201+ if (_rx_pkt )
202+ _rx_pkt. reset ();
189203}
190204
191205IPAddress Arduino_10BASE_T1S_UDP::remoteIP ()
192206{
193- if (_rx_pkt_list. size () )
194- return _rx_pkt_list. front () ->remoteIP ();
207+ if (_rx_pkt )
208+ return _rx_pkt ->remoteIP ();
195209 else
196210 return IPAddress ();
197211}
198212
199213uint16_t Arduino_10BASE_T1S_UDP::remotePort ()
200214{
201- if (_rx_pkt_list. size () )
202- return _rx_pkt_list. front () ->remotePort ();
215+ if (_rx_pkt )
216+ return _rx_pkt ->remotePort ();
203217 else
204218 return 0 ;
205219}
0 commit comments