UDP: do not discard bytes in rx_buffer at start of receive #52
+2
−6
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem:
There was an issue with the UDP server implementation (same for the client) when a connected UDP client was not sending proper mavlink v2 message. After accidentally receiving the mavlink v2 magic starter byte, it tried to receive the rest of the message. Parsing the mavlink header was fine, but the payload length could end up being the max value. The receive function is then blocked in here: https://github.com/Auterion/libmav/blob/main/include/mav/UDPServer.h#L109
Where it tries to receive data from the UDP socket until it finds a datagram which is larger than the requested read size, while discarding smaller datagrams.
Solution:
Do not discard the bytes in the RX_buffer when a new read from the datagram is requested. it makes no sense to discard bytes after the starter byte has been found. Instead accumulate them in the buffer until the size is reached. This way at least it can get out of the receive function on garbage data. Buffer is still flushed on the markSync call.