Called when a connection undergoes a state transition.
| 242 | |
| 243 | // Called when a connection undergoes a state transition. |
| 244 | void OnSteamNetConnectionStatusChanged( SteamNetConnectionStatusChangedCallback_t *pInfo ) |
| 245 | { |
| 246 | // What's the state of the connection? |
| 247 | switch ( pInfo->m_info.m_eState ) |
| 248 | { |
| 249 | case k_ESteamNetworkingConnectionState_ClosedByPeer: |
| 250 | case k_ESteamNetworkingConnectionState_ProblemDetectedLocally: |
| 251 | |
| 252 | TEST_Printf( "[%s] %s, reason %d: %s\n", |
| 253 | pInfo->m_info.m_szConnectionDescription, |
| 254 | ( pInfo->m_info.m_eState == k_ESteamNetworkingConnectionState_ClosedByPeer ? "closed by peer" : "problem detected locally" ), |
| 255 | pInfo->m_info.m_eEndReason, |
| 256 | pInfo->m_info.m_szEndDebug |
| 257 | ); |
| 258 | |
| 259 | if ( g_hConnection == pInfo->m_hConn ) |
| 260 | { |
| 261 | // Print route info before closing the handle; GetConnectionInfo won't work after. |
| 262 | // The non-server side prints this in the main loop; the server side does it here |
| 263 | // since it never initiates the close itself. |
| 264 | if ( !g_bExpectFailure && g_eTestRole == k_ETestRole_Server ) |
| 265 | PrintRouteInfo(); |
| 266 | |
| 267 | // Close our end |
| 268 | SteamNetworkingSockets()->CloseConnection( pInfo->m_hConn, 0, nullptr, false ); |
| 269 | g_hConnection = k_HSteamNetConnection_Invalid; |
| 270 | g_bConnected = false; |
| 271 | |
| 272 | if ( g_bExpectFailure ) |
| 273 | { |
| 274 | // Connection failure is the expected outcome. |
| 275 | // ProblemDetectedLocally (or ClosedByPeer with non-app reason) = expected. |
| 276 | // ClosedByPeer with App_Generic = the peer completed successfully, which is wrong. |
| 277 | bool bUnexpectedSuccess = ( pInfo->m_info.m_eState == k_ESteamNetworkingConnectionState_ClosedByPeer ) |
| 278 | && ( pInfo->m_info.m_eEndReason == k_ESteamNetConnectionEnd_App_Generic ); |
| 279 | if ( bUnexpectedSuccess ) |
| 280 | { |
| 281 | TEST_Printf( "ERROR: connection closed cleanly, but failure was expected\n" ); |
| 282 | Quit( 1 ); |
| 283 | } |
| 284 | TEST_Printf( "Connection failed as expected\n" ); |
| 285 | SteamNetworkingSocketsLib::TEST_ICE_ctr_Print(); |
| 286 | } |
| 287 | else |
| 288 | { |
| 289 | bool bError = ( pInfo->m_info.m_eState == k_ESteamNetworkingConnectionState_ProblemDetectedLocally ) |
| 290 | || ( pInfo->m_info.m_eEndReason != k_ESteamNetConnectionEnd_App_Generic ); |
| 291 | if ( bError ) |
| 292 | Quit( 1 ); |
| 293 | |
| 294 | if ( g_eTestRole == k_ETestRole_Server ) |
| 295 | SteamNetworkingSocketsLib::TEST_ICE_ctr_Print(); |
| 296 | } |
| 297 | |
| 298 | // Clean close (or expected failure) -- main loop starts next iteration or exits. |
| 299 | ++g_nConnectionsDone; |
| 300 | } |
| 301 | else |
nothing calls this directly
no test coverage detected