TcpClient does not send incomplete packets. #2721
Merged
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.
Before this Pull Request, when the microprocessor runs out of memory while calling
TcpClient::send
, this method could send an incomplete packet. SinceTcpClient::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 aMemoryDataStream
(by a call to MemoryDataStream::write). According to its implementation, when it is not possible to allocate enough additional memory to holddata
,MemoryDataStream
stores "as much as possible" in the space that could be allocated. For aTcpClient
, 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 theMemoryDataStream
. This makes sure only complete messages are sent.