mirror of
https://github.com/BeamMP/BeamMP-Launcher.git
synced 2026-10-20 07:34:15 +00:00
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:
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user