heinrich5991 / libtw2

Some Teeworlds stuff in Rust.™
Apache License 2.0
49 stars 17 forks source link

Document empty packets #82

Closed ChillerDragon closed 11 months ago

ChillerDragon commented 1 year ago

I was about to open a pr to change that. When I realized this is probably intentional design. When there is nothing to send but we still want to request a resend it is fine to just send the header without payload to inform the other side. Something to watch out for when reimplementing the protocol.

index d101e700..83a7966c 100644
--- a/src/engine/shared/network_conn.cpp
+++ b/src/engine/shared/network_conn.cpp
@@ -86,8 +86,7 @@ void CNetConnection::SignalResend()

 int CNetConnection::Flush()
 {
-       int NumChunks = m_Construct.m_NumChunks;
-       if(!NumChunks && !m_Construct.m_Flags)
+       if(!m_Construct.m_DataSize)
                return 0;

        // send of the packets
@@ -100,7 +99,7 @@ int CNetConnection::Flush()

        // clear construct so we can start building a new package
        mem_zero(&m_Construct, sizeof(m_Construct));
-       return NumChunks;
+       return m_Construct.m_NumChunks;
 }

 int CNetConnection::QueueChunkEx(int Flags, int DataSize, const void *pData, int Sequence)