Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UDP: do not discard bytes in rx_buffer at start of receive #52

Merged
merged 1 commit into from
Nov 18, 2024

Conversation

KonradRudin
Copy link
Contributor

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.

Copy link
Contributor

@bkueng bkueng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice find, makes sense

@KonradRudin KonradRudin merged commit 25420b8 into main Nov 18, 2024
3 of 4 checks passed
@KonradRudin KonradRudin deleted the fix_udp_discarding_bytes branch November 18, 2024 16:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants