MCPcopy Create free account
hub / github.com/ValveSoftware/GameNetworkingSockets / ReceiveAndCheckMessages

Function ReceiveAndCheckMessages

tests/test_p2p.cpp:209–241  ·  view source on GitHub ↗

Drain all pending received messages and verify their counters. Reliable counter mismatches are fatal; unreliable are expected and just logged.

Source from the content-addressed store, hash-verified

207// Drain all pending received messages and verify their counters.
208// Reliable counter mismatches are fatal; unreliable are expected and just logged.
209void ReceiveAndCheckMessages()
210{
211 for (;;)
212 {
213 SteamNetworkingMessage_t *pMsg = nullptr;
214 int r = SteamNetworkingSockets()->ReceiveMessagesOnConnection( g_hConnection, &pMsg, 1 );
215 assert( r == 0 || r == 1 ); // <0 indicates an error
216 if ( r == 0 )
217 break;
218
219 if ( pMsg->m_cbSize < (int)sizeof(int32_t) )
220 TEST_Fatal( "Received message too short (%d bytes)", pMsg->m_cbSize );
221
222 int32_t nCounter;
223 memcpy( &nCounter, pMsg->GetData(), sizeof(nCounter) );
224 // For received messages, only the k_nSteamNetworkingSend_Reliable bit is valid in m_nFlags.
225 bool bReliable = ( pMsg->m_nFlags & k_nSteamNetworkingSend_Reliable ) != 0;
226 pMsg->Release();
227
228 if ( bReliable )
229 {
230 if ( nCounter != g_nRecvExpectedReliable )
231 TEST_Fatal( "Reliable message counter mismatch: expected %d, got %d", g_nRecvExpectedReliable, nCounter );
232 ++g_nRecvExpectedReliable;
233 }
234 else
235 {
236 if ( nCounter != g_nRecvExpectedUnreliable )
237 TEST_Printf( "Unreliable message %d arrived out of order (expected %d)\n", nCounter, g_nRecvExpectedUnreliable );
238 g_nRecvExpectedUnreliable = nCounter + 1;
239 }
240 }
241}
242
243// Called when a connection undergoes a state transition.
244void OnSteamNetConnectionStatusChanged( SteamNetConnectionStatusChangedCallback_t *pInfo )

Callers 1

mainFunction · 0.85

Calls 6

SteamNetworkingSocketsFunction · 0.85
TEST_FatalFunction · 0.85
TEST_PrintfFunction · 0.85
GetDataMethod · 0.80
ReleaseMethod · 0.45

Tested by

no test coverage detected