Fix WebSocket proxy not gluing segmented TCP packets back together

This commit is contained in:
scatterflower 2021-07-27 17:44:26 -05:00
parent 4c5954e9c0
commit 78f3e1d3d1
2 changed files with 24 additions and 0 deletions

View File

@ -104,6 +104,16 @@ private:
* @brief The WebSocket representing an incoming connection.
*/
QWebSocket* web_socket;
/**
* @brief Stores partial packets in case they don't all come through the TCP socket at once
*/
QByteArray partial_packet;
/**
* @brief Flag that is set when packets are segmented
*/
bool is_segmented = false;
};
#endif // WS_CLIENT_H

View File

@ -26,6 +26,20 @@ void WSClient::onWsData(QString message)
void WSClient::onTcpData()
{
QByteArray tcp_message = tcp_socket->readAll();
if (!tcp_message.endsWith("#%")) {
partial_packet.append(tcp_message);
is_segmented = true;
return;
}
if (is_segmented) {
partial_packet.append(tcp_message);
tcp_message = partial_packet;
partial_packet.clear();
is_segmented = false;
}
// Workaround for WebAO bug needing every packet in its own message
QStringList all_packets = QString::fromUtf8(tcp_message).split("%");
all_packets.removeLast(); // Remove empty space after final delimiter