diff options
-rw-r--r-- | src/ClientHandle.cpp | 27 | ||||
-rw-r--r-- | src/ClientHandle.h | 6 |
2 files changed, 28 insertions, 5 deletions
diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 10920496d..c774a92c2 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -1824,10 +1824,7 @@ void cClientHandle::SendData(const char * a_Data, size_t a_Size) } cCSLock Lock(m_CSOutgoingData); - if (m_Link != nullptr) - { - m_Link->Send(a_Data, a_Size); - } + m_OutgoingData.append(a_Data, a_Size); } @@ -1888,6 +1885,17 @@ void cClientHandle::Tick(float a_Dt) { m_Protocol->DataReceived(IncomingData.data(), IncomingData.size()); } + + // Send any queued outgoing data: + AString OutgoingData; + { + cCSLock Lock(m_CSOutgoingData); + std::swap(OutgoingData, m_OutgoingData); + } + if ((m_Link != nullptr) && !OutgoingData.empty()) + { + m_Link->Send(OutgoingData.data(), OutgoingData.size()); + } m_TicksSinceLastPacket += 1; if (m_TicksSinceLastPacket > 600) // 30 seconds time-out @@ -1976,6 +1984,17 @@ void cClientHandle::ServerTick(float a_Dt) m_Protocol->DataReceived(IncomingData.data(), IncomingData.size()); } + // Send any queued outgoing data: + AString OutgoingData; + { + cCSLock Lock(m_CSOutgoingData); + std::swap(OutgoingData, m_OutgoingData); + } + if ((m_Link != nullptr) && !OutgoingData.empty()) + { + m_Link->Send(OutgoingData.data(), OutgoingData.size()); + } + if (m_State == csAuthenticated) { StreamNextChunk(); diff --git a/src/ClientHandle.h b/src/ClientHandle.h index f5b7faede..8129d6a50 100644 --- a/src/ClientHandle.h +++ b/src/ClientHandle.h @@ -376,9 +376,13 @@ private: Protected by m_CSIncomingData. */ AString m_IncomingData; - /** Protects data going out through m_Link against multi-threaded sending. */ + /** Protects m_OutgoingData against multithreaded access. */ cCriticalSection m_CSOutgoingData; + /** Buffer for storing outgoing data from any thread; will get sent in Tick() (to prevent deadlocks). + Protected by m_CSOutgoingData. */ + AString m_OutgoingData; + Vector3d m_ConfirmPosition; cPlayer * m_Player; |