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

Function Test_Connection

tests/test_connection.cpp:498–573  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

496}
497
498static void Test_Connection( ETestConnectionMode eMode, const SteamNetworkingIPAddr &addrServerBind, const SteamNetworkingIPAddr &addrClientConnect )
499{
500 static const char *const k_rgszModeName[] = { "Cursory", "Normal", "Soak" };
501 TEST_Printf( "***************************************************\n" );
502 TEST_Printf( "Mode: %s\n", k_rgszModeName[ (int)eMode ] );
503 TEST_Printf( "Server bind: %s\n", SteamNetworkingIPAddrRender( addrServerBind ).c_str() );
504 TEST_Printf( "Client connect: %s\n", SteamNetworkingIPAddrRender( addrClientConnect ).c_str() );
505 TEST_Printf( "***************************************************\n" );
506
507 SteamNetworkingUtils()->SetGlobalCallback_SteamNetConnectionStatusChanged( OnSteamNetConnectionStatusChanged );
508
509 CloseConnections();
510
511 ISteamNetworkingSockets *pSteamSocketNetworking = SteamNetworkingSockets();
512
513 // Initiate connection
514 g_hSteamListenSocket = pSteamSocketNetworking->CreateListenSocketIP( addrServerBind, 0, nullptr );
515 g_peerClient.m_hSteamNetConnection = pSteamSocketNetworking->ConnectByIPAddress( addrClientConnect, 0, nullptr );
516 pSteamSocketNetworking->SetConnectionName( g_peerClient.m_hSteamNetConnection, "Client" );
517
518 g_peerClient.SetConnectionConfig();
519
520// // Send a few random message, before we get connected, just to test that case
521// g_peerClient.SendRandomMessage( true );
522// g_peerClient.SendRandomMessage( true );
523// g_peerClient.SendRandomMessage( true );
524
525 // Wait for connection to complete
526 while ( !g_peerClient.m_bIsConnected || !g_peerServer.m_bIsConnected )
527 TEST_PumpCallbacks();
528
529 auto Test = [eMode]( int rate, float loss, int lag, float reorderPct, int reorderLag )
530 {
531 TestNetworkConditions( rate, loss, lag, reorderPct, reorderLag, false, eMode );
532 TestNetworkConditions( rate, loss, lag, reorderPct, reorderLag, true, eMode );
533 };
534
535 // ETestConnectionMode::Cursory )
536 {
537 Test( 128000, 10, 50, 2, 50 ); // Low bandwidth, high packet loss
538 }
539
540 if ( eMode >= ETestConnectionMode::Normal )
541 {
542 Test( 1000000, 5, 10, 1, 10 ); // Medium bandwidth, still pretty bad packet loss
543
544 // Zero loss so acks flow freely (stop_waiting tracks within one RTT of
545 // current packet number). Heavy reorder builds reliable stream fragments
546 // without the retransmission backlog that keeps stop_waiting far behind.
547 TestNetworkConditions( 2000000, 0, 50, 30, 40, false, eMode );
548 }
549
550 if ( eMode >= ETestConnectionMode::Soak )
551 {
552 Test( 64000, 20, 100, 4, 50 ); // low bandwidth, terrible packet loss
553 Test( 1000000, 20, 100, 4, 10 ); // high bandwidth, terrible packet loss
554 Test( 1000000, 2, 5, 2, 1 ); // wifi (high bandwidth, low packet loss, occasional reordering with very small delay)
555 Test( 2000000, 0, 0, 0, 0 ); // LAN (high bandwidth, negligible lag/loss)

Callers 2

Test_quickFunction · 0.85
Test_soakFunction · 0.85

Calls 13

TEST_PrintfFunction · 0.85
SteamNetworkingUtilsFunction · 0.85
CloseConnectionsFunction · 0.85
SteamNetworkingSocketsFunction · 0.85
TEST_PumpCallbacksFunction · 0.85
TestNetworkConditionsFunction · 0.85
CreateListenSocketIPMethod · 0.80
ConnectByIPAddressMethod · 0.80
SetConnectionNameMethod · 0.80
SetConnectionConfigMethod · 0.80

Tested by

no test coverage detected