Fix TCP connection drops caused by thread interleaving in TCPSend

This commit addresses the mysterious connection drops that occur under heavy load.

1. Added `TCPSendMutex` to `TCPSend` in `VehicleEvent.cpp`.
While `UDPSend`, `GameSend`, and `CoreSend` all had dedicated mutexes, `TCPSend` was missing one. This allowed the background `AutoPing` thread to occasionally collide with the main event loop while sending data. This interleaving corrupted the TCP headers, causing the server to instantly terminate the connection due to malformed packets. `TCPSend` is now safely locked with a `std::scoped_lock`.
This commit is contained in:
Unshown
2026-08-24 13:23:50 +02:00
parent 92cf7a9c67
commit 81cbda0d56
+5
View File
@@ -10,6 +10,7 @@
#include <chrono>
#include <iostream>
#include <vector>
#include <mutex>
#if defined(_WIN32)
#include <ws2tcpip.h>
@@ -50,7 +51,11 @@ void UUl(const std::string& R) {
UlStatus = "UlDisconnected: " + R;
}
std::mutex TCPSendMutex;
void TCPSend(const std::string& Data, uint64_t Sock) {
std::scoped_lock lock(TCPSendMutex);
if (Sock == -1) {
Terminate = true;
UUl("Invalid Socket");