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

TcpClient does not send incomplete packets. #2721

Merged
merged 1 commit into from
Mar 7, 2024

Conversation

acburigo
Copy link
Contributor

@acburigo acburigo commented Mar 5, 2024

Before this Pull Request, when the microprocessor runs out of memory while calling TcpClient::send, this method could send an incomplete packet. Since TcpClient::send does not return the number of bytes actually sent, there's no way to know which part of the message was sent and which part still needs to be sent. Therefore - assuming we keep the interface constant - we should not allow a message to be sent incompletely.

More specifically, when one calls TcpClient::send, the data argument is written to a MemoryDataStream (by a call to MemoryDataStream::write). According to its implementation, when it is not possible to allocate enough additional memory to hold data, MemoryDataStream stores "as much as possible" in the space that could be allocated. For a TcpClient, this may not be a desirable behavior since this allows incomplete messages to be sent, while there's no way to know how much of the packet was actually sent.

My pull request ensures there's enough memory to hold data before writing it to the MemoryDataStream. This makes sure only complete messages are sent.

Copy link

what-the-diff bot commented Mar 5, 2024

PR Summary

  • Improvement to Ensure Data Buffer Capacity in TcpClient.cpp
    • An addition was made to the send function in the TcpClient.cpp file to validate enough buffer space before data is written. This will help prevent data loss and potential application errors from occurring.
  • Enhancement of Data Write Operation
    • The function responsible for writing data in the TcpClient.cpp file has been updated. This ensures data is accurately and efficiently written into the buffer, contributing to smoother and more robust data transfer operations.

@mikee47
Copy link
Contributor

mikee47 commented Mar 6, 2024

@acburigo I think I see what's going on here, but could you add a brief description of the issue you've encountered, what the problem is and how this fixes it?

@acburigo
Copy link
Contributor Author

acburigo commented Mar 6, 2024

Sorry! I have added a description to my Pull Request. I hope this makes it clearer.
@mikee47 @slaff

@slaff slaff added this to the 5.2.0 milestone Mar 7, 2024
@slaff slaff merged commit 9e4b251 into SmingHub:develop Mar 7, 2024
46 checks passed
@slaff slaff removed the 3 - Review label Mar 7, 2024
@mikee47
Copy link
Contributor

mikee47 commented Mar 7, 2024

@acburigo Thank you for the fix!

@slaff
Copy link
Contributor

slaff commented Mar 7, 2024

... Thank you for the fix!

@acburigo And welcome to the contributors team :)

@slaff slaff mentioned this pull request May 8, 2024
5 tasks
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.

3 participants