summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattes D <github@xoft.cz>2015-01-26 14:49:51 +0100
committerMattes D <github@xoft.cz>2015-01-27 14:53:38 +0100
commit19d463ae1c0faaf08a0783a01db81eae0a271b62 (patch)
treee601cdfb70dad08ef469cb00accc52aa4ff0ad40
parentAdded network termination called at app exit. (diff)
downloadcuberite-19d463ae1c0faaf08a0783a01db81eae0a271b62.tar
cuberite-19d463ae1c0faaf08a0783a01db81eae0a271b62.tar.gz
cuberite-19d463ae1c0faaf08a0783a01db81eae0a271b62.tar.bz2
cuberite-19d463ae1c0faaf08a0783a01db81eae0a271b62.tar.lz
cuberite-19d463ae1c0faaf08a0783a01db81eae0a271b62.tar.xz
cuberite-19d463ae1c0faaf08a0783a01db81eae0a271b62.tar.zst
cuberite-19d463ae1c0faaf08a0783a01db81eae0a271b62.zip
-rw-r--r--src/ClientHandle.cpp27
-rw-r--r--src/ClientHandle.h6
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;