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

Function Test_pipe

tests/test_connection.cpp:1206–1287  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1204}
1205
1206void Test_pipe()
1207{
1208 TEST_Printf( "***************************************************\n" );
1209 TEST_Printf( "Pipe (socket pair, no network loopback)\n" );
1210 TEST_Printf( "***************************************************\n" );
1211
1212 // CreateSocketPair with bUseNetworkLoopback=false: pure internal buffer path,
1213 // no encryption, no packet fragmentation, no network stack involvement.
1214 HSteamNetConnection hAlice, hBob;
1215 SteamNetworkingIdentity identAlice, identBob;
1216 identAlice.SetGenericString( "alice" );
1217 identBob.SetGenericString( "bob" );
1218 // NOTE: each pPeerIdentity is the remote identity seen by the *corresponding* connection.
1219 assert( SteamNetworkingSockets()->CreateSocketPair( &hAlice, &hBob, false, &identBob, &identAlice ) );
1220
1221 // Verify each end observes the correct remote identity.
1222 {
1223 SteamNetConnectionInfo_t infoAlice, infoBob;
1224 assert( SteamNetworkingSockets()->GetConnectionInfo( hAlice, &infoAlice ) );
1225 assert( SteamNetworkingSockets()->GetConnectionInfo( hBob, &infoBob ) );
1226 assert( infoAlice.m_identityRemote == identBob );
1227 assert( infoBob.m_identityRemote == identAlice );
1228 }
1229
1230 // Wire up to the global peer state used by TestNetworkConditions / PumpCallbacksAndMakeSureStillConnected.
1231 g_peerClient.Reset();
1232 g_peerServer.Reset();
1233 g_peerClient.m_hSteamNetConnection = hAlice;
1234 g_peerClient.m_bIsConnected = true;
1235 g_peerClient.SetConnectionConfig();
1236 g_peerServer.m_hSteamNetConnection = hBob;
1237 g_peerServer.m_bIsConnected = true;
1238 g_peerServer.SetConnectionConfig();
1239
1240 // Cursory connection test. Fake loss/lag config has no effect on a pipe
1241 // (no network path), but the send/receive loop still exercises the connection.
1242 TestNetworkConditions( 10*1000*1000, 0, 0, 0, 0, false, ETestConnectionMode::Cursory );
1243
1244 // Zero-copy: for a pipe connection the received message must point at the
1245 // exact same data buffer that was handed to SendMessages -- no copy through
1246 // any network or encryption layer.
1247 {
1248 SteamNetworkingMessage_t *pSendMsg = SteamNetworkingUtils()->AllocateMessage( 256 );
1249 pSendMsg->m_conn = hAlice;
1250 pSendMsg->m_nFlags = k_nSteamNetworkingSend_Reliable;
1251 void *pSendData = pSendMsg->m_pData;
1252
1253 int64 nMsgNum = 0;
1254 SteamNetworkingSockets()->SendMessages( 1, &pSendMsg, &nMsgNum, true );
1255 assert( nMsgNum > 0 );
1256
1257 SteamNetworkingMessage_t *pRecvMsg = nullptr;
1258 int nRecv = SteamNetworkingSockets()->ReceiveMessagesOnConnection( hBob, &pRecvMsg, 1 );
1259 assert( nRecv == 1 );
1260 assert( pRecvMsg->m_pData == pSendData ); // zero-copy: must be the same pointer
1261 pRecvMsg->Release();
1262 }
1263

Callers

nothing calls this directly

Calls 14

TEST_PrintfFunction · 0.85
SteamNetworkingSocketsFunction · 0.85
TestNetworkConditionsFunction · 0.85
SteamNetworkingUtilsFunction · 0.85
SetGenericStringMethod · 0.80
CreateSocketPairMethod · 0.80
GetConnectionInfoMethod · 0.80
SetConnectionConfigMethod · 0.80
AllocateMessageMethod · 0.80
SendMessagesMethod · 0.80
ResetMethod · 0.45

Tested by

no test coverage detected