Fix websocket dropping messages for WSLPeer #98167
Closed
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.
Supercedes #98128
Fixes #70738
Address WSLPeer dropping messages
Currently the behavior of wsl_peer allows messages that would be able to fit into the in_buffer to be dropped completely while being received.
To address this issue the method
WSLPeer::_wsl_on_frame_start_callback
has been implemented as a callback from wslay. It is used to grab the size of the incoming message and use that size withinWSLPeer::_wsl_recv_callback
to refuse incoming packets for that message until space is available to hold the entire message.on_frame_recv_start_callback
This callback function is called with an argument that includes the incoming payload length. Using this length we can compare it to the free space currently in the in_buffer. This gives us the ability to wait on receiving the message untill enough space is available in the in_buffer to receive it.
uint64_t length_needed = 0;
This public member variable was introduced to store the size of the incoming message and is used when telling wslay to start accepting packets for the message.
WSLPeer::_wsl_recv_callback
Using the
length_needed
variable defined by theon_frame_recv_start_callback
we are able to check if the current space available is sufficient to accept the incoming message. If it's not we continue waiting until enough space has opened up.space_left function
This function was added to the
PacketBuffer
class to allow callback functions inwsl_peer.cpp
to get the current freespace in the in_buffer.@RadenTheFolf
This PR is generously donated by Redot.