Drain all pending received messages and verify their counters. Reliable counter mismatches are fatal; unreliable are expected and just logged.
| 207 | // Drain all pending received messages and verify their counters. |
| 208 | // Reliable counter mismatches are fatal; unreliable are expected and just logged. |
| 209 | void 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. |
| 244 | void OnSteamNetConnectionStatusChanged( SteamNetConnectionStatusChangedCallback_t *pInfo ) |
no test coverage detected