mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2025-07-01 23:35:41 +00:00
fix race condition in packet queueing
This commit is contained in:
parent
eaa6b5322f
commit
e4d6c86919
@ -58,6 +58,7 @@ public:
|
|||||||
[[nodiscard]] std::queue<std::string>& MissedPacketQueue() { return mMissedPacketsDuringSyncing; }
|
[[nodiscard]] std::queue<std::string>& MissedPacketQueue() { return mMissedPacketsDuringSyncing; }
|
||||||
[[nodiscard]] const std::queue<std::string>& MissedPacketQueue() const { return mMissedPacketsDuringSyncing; }
|
[[nodiscard]] const std::queue<std::string>& MissedPacketQueue() const { return mMissedPacketsDuringSyncing; }
|
||||||
[[nodiscard]] size_t MissedPacketQueueSize() const { return mMissedPacketsDuringSyncing.size(); }
|
[[nodiscard]] size_t MissedPacketQueueSize() const { return mMissedPacketsDuringSyncing.size(); }
|
||||||
|
[[nodiscard]] std::mutex& MissedPacketQueueMutex() const { return mMissedPacketsMutex; }
|
||||||
void SetIsConnected(bool NewIsConnected) { mIsConnected = NewIsConnected; }
|
void SetIsConnected(bool NewIsConnected) { mIsConnected = NewIsConnected; }
|
||||||
[[nodiscard]] TServer& Server() const;
|
[[nodiscard]] TServer& Server() const;
|
||||||
void UpdatePingTime();
|
void UpdatePingTime();
|
||||||
@ -68,7 +69,7 @@ private:
|
|||||||
bool mIsConnected = false;
|
bool mIsConnected = false;
|
||||||
bool mIsSynced = false;
|
bool mIsSynced = false;
|
||||||
bool mIsSyncing = false;
|
bool mIsSyncing = false;
|
||||||
std::mutex mMissedPacketsMutex;
|
mutable std::mutex mMissedPacketsMutex;
|
||||||
std::queue<std::string> mMissedPacketsDuringSyncing;
|
std::queue<std::string> mMissedPacketsDuringSyncing;
|
||||||
std::set<std::string> mIdentifiers;
|
std::set<std::string> mIdentifiers;
|
||||||
bool mIsGuest = false;
|
bool mIsGuest = false;
|
||||||
|
@ -338,6 +338,7 @@ std::shared_ptr<TClient> TNetwork::CreateClient(SOCKET TCPSock) {
|
|||||||
|
|
||||||
bool TNetwork::TCPSend(TClient& c, const std::string& Data, bool IsSync) {
|
bool TNetwork::TCPSend(TClient& c, const std::string& Data, bool IsSync) {
|
||||||
if (!IsSync) {
|
if (!IsSync) {
|
||||||
|
std::unique_lock Lock(c.MissedPacketQueueMutex());
|
||||||
if (c.IsSyncing()) {
|
if (c.IsSyncing()) {
|
||||||
c.EnqueueMissedPacketDuringSyncing(Data);
|
c.EnqueueMissedPacketDuringSyncing(Data);
|
||||||
return true;
|
return true;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user