Skip to content

NetworkUDP - in parsePacket handle previous parsed packet #10239

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

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion libraries/Network/src/NetworkUdp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,10 @@ void NetworkUDP::flush() {}

int NetworkUDP::parsePacket() {
if (rx_buffer) {
return 0;
if (rx_buffer->full()) { // packet was not read yet
return rx_buffer->available();
Copy link
Member

Choose a reason for hiding this comment

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

can you show a benefit from returning the previous packet len more than once? If code did not care about it the first time, why should it care after that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

for the library it is better than destroying it then allocate the next then destroy it ...

Copy link
Member

Choose a reason for hiding this comment

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

library will not destroy it. It will just return 0, because old packet is still there and new one was not received. The point of returning positive length is to signal that a new packet has been received. This happens only once per packet.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

but the PR is about not returning a zero if the packet was not read until the end

}
clear(); // discard the rest of the packet
Copy link
Member

Choose a reason for hiding this comment

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

What will happen in you call parsePacket from one thread, but you read it's data from another?

}
struct sockaddr_storage si_other_storage; // enough storage for v4 and v6
socklen_t slen = sizeof(sockaddr_storage);
Expand Down
Loading