MCPcopy Create free account
hub / github.com/ddnet/ddnet / QueueChunkEx

Method QueueChunkEx

src/engine/shared/network_conn.cpp:122–174  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

120}
121
122int CNetConnection::QueueChunkEx(int Flags, int DataSize, const void *pData, int Sequence)
123{
124 if(m_State == EState::OFFLINE || m_State == EState::ERROR)
125 return -1;
126
127 unsigned char *pChunkData;
128
129 // check if we have space for it, if not, flush the connection
130 if(m_Construct.m_DataSize + DataSize + NET_MAX_CHUNKHEADERSIZE > (int)sizeof(m_Construct.m_aChunkData) - (int)sizeof(SECURITY_TOKEN) ||
131 m_Construct.m_NumChunks == NET_MAX_PACKET_CHUNKS)
132 {
133 Flush();
134 }
135
136 // pack all the data
137 CNetChunkHeader Header;
138 Header.m_Flags = Flags;
139 Header.m_Size = DataSize;
140 Header.m_Sequence = Sequence;
141 pChunkData = &m_Construct.m_aChunkData[m_Construct.m_DataSize];
142 pChunkData = Header.Pack(pChunkData, m_Sixup ? 6 : 4);
143 mem_copy(pChunkData, pData, DataSize);
144 pChunkData += DataSize;
145
146 //
147 m_Construct.m_NumChunks++;
148 m_Construct.m_DataSize = (int)(pChunkData - m_Construct.m_aChunkData);
149
150 // set packet flags as well
151
152 if(Flags & NET_CHUNKFLAG_VITAL && !(Flags & NET_CHUNKFLAG_RESEND))
153 {
154 // save packet if we need to resend
155 CNetChunkResend *pResend = m_Buffer.Allocate(sizeof(CNetChunkResend) + DataSize);
156 if(pResend)
157 {
158 pResend->m_Sequence = Sequence;
159 pResend->m_Flags = Flags;
160 pResend->m_DataSize = DataSize;
161 pResend->m_pData = (unsigned char *)(pResend + 1);
162 pResend->m_FirstSendTime = time_get();
163 pResend->m_LastSendTime = pResend->m_FirstSendTime;
164 mem_copy(pResend->m_pData, pData, DataSize);
165 }
166 else
167 {
168 // out of buffer, don't save the packet and hope nobody will ask for resend
169 return -1;
170 }
171 }
172
173 return 0;
174}
175
176int CNetConnection::QueueChunk(int Flags, int DataSize, const void *pData)
177{

Callers

nothing calls this directly

Calls 4

mem_copyFunction · 0.85
time_getFunction · 0.85
PackMethod · 0.45
AllocateMethod · 0.45

Tested by

no test coverage detected