Fixed a deadlock in cClientHandle network sending.
This commit is contained in:
parent
053362e604
commit
19d463ae1c
@ -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();
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user