| 188 | } |
| 189 | |
| 190 | static void Recv( ISteamNetworkingSockets *pSteamSocketNetworking ) |
| 191 | { |
| 192 | |
| 193 | while ( true ) |
| 194 | { |
| 195 | SFakePeer *pConnection = &g_peerServer; |
| 196 | ISteamNetworkingMessage *pIncomingMsg = nullptr; |
| 197 | int numMsgs = pSteamSocketNetworking->ReceiveMessagesOnConnection( pConnection->m_hSteamNetConnection, &pIncomingMsg, 1 ); |
| 198 | if ( numMsgs <= 0 ) |
| 199 | { |
| 200 | pConnection = &g_peerClient; |
| 201 | numMsgs = pSteamSocketNetworking->ReceiveMessagesOnConnection( pConnection->m_hSteamNetConnection, &pIncomingMsg, 1 ); |
| 202 | if ( numMsgs <= 0 ) |
| 203 | return; |
| 204 | } |
| 205 | |
| 206 | const TestMsg *pTestMsg = static_cast<const TestMsg*>( pIncomingMsg->GetData() ); |
| 207 | |
| 208 | // Size makes sense? |
| 209 | assert( sizeof(*pTestMsg) - sizeof(pTestMsg->m_data) + pTestMsg->m_cbSize == pIncomingMsg->GetSize() ); |
| 210 | |
| 211 | // Check for sequence number anomaly. |
| 212 | int64 &nExpectedMsgNum = pTestMsg->m_bReliable ? pConnection->m_nReliableExpectedRecvMsg : pConnection->m_nExpectedRecvMsg; |
| 213 | if ( pTestMsg->m_nMsgNum != nExpectedMsgNum && pTestMsg->m_bReliable ) |
| 214 | { |
| 215 | |
| 216 | // Print that it happened. |
| 217 | TEST_Printf( |
| 218 | "Recv: %s, %s MISMATCH NUM wanted %lld got %lld\n", |
| 219 | pConnection->m_sName.c_str(), |
| 220 | pTestMsg->m_bReliable ? "RELIABLE" : "UNRELIABLE", |
| 221 | (long long)nExpectedMsgNum, |
| 222 | (long long)pTestMsg->m_nMsgNum ); |
| 223 | |
| 224 | // This should not happen for reliable messages! |
| 225 | assert( !pTestMsg->m_bReliable ); |
| 226 | } |
| 227 | |
| 228 | float flDelay = ( SteamNetworkingUtils()->GetLocalTimestamp() - pTestMsg->m_usecWhenSent ) * 1e-6f; |
| 229 | pConnection->m_nRecvInterval += pIncomingMsg->GetSize(); |
| 230 | if ( pTestMsg->m_bReliable ) |
| 231 | { |
| 232 | pConnection->m_flReliableMsgDelay += ( flDelay - pConnection->m_flReliableMsgDelay ) * .25f; |
| 233 | } |
| 234 | else |
| 235 | { |
| 236 | pConnection->m_flUnreliableMsgDelay += ( flDelay - pConnection->m_flUnreliableMsgDelay ) * .25f; |
| 237 | } |
| 238 | |
| 239 | nExpectedMsgNum = pTestMsg->m_nMsgNum + 1; |
| 240 | pIncomingMsg->Release(); |
| 241 | } |
| 242 | } |
| 243 | |
| 244 | void OnSteamNetConnectionStatusChanged( SteamNetConnectionStatusChangedCallback_t *pInfo ) |
| 245 | { |
no test coverage detected