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

Method SendRandomMessage

tests/test_connection.cpp:122–167  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

120 }
121
122 void SendRandomMessage( bool bReliable, int cbMaxSize )
123 {
124 TestMsg msg;
125 msg.m_bReliable = bReliable;
126 msg.m_usecWhenSent = SteamNetworkingUtils()->GetLocalTimestamp();
127 msg.m_cbSize = std::uniform_int_distribution<>( 20, cbMaxSize )( g_rand );
128 //bIsReliable = false;
129 //nBytes = 1200-13;
130
131 msg.m_nMsgNum = msg.m_bReliable ? ++m_nReliableSendMsgCount : ++m_nUnreliableSendMsgCount;
132 for ( int n = 0; n < msg.m_cbSize; ++n )
133 {
134 msg.m_data[n] = (uint8)( msg.m_nMsgNum + n );
135 }
136
137 int cbSend = (int)( sizeof(msg) - sizeof(msg.m_data) + msg.m_cbSize );
138 m_nSendInterval += cbSend;
139
140 EResult result = SteamNetworkingSockets()->SendMessageToConnection(
141 m_hSteamNetConnection,
142 &msg,
143 cbSend,
144 msg.m_bReliable ? k_nSteamNetworkingSend_Reliable : k_nSteamNetworkingSend_Unreliable, nullptr );
145
146 if ( result != k_EResultOK )
147 {
148 TEST_Printf( "***ERROR ON Send: %s %.3f %s message %lld, %d bytes (pending %d bytes)\n",
149 m_sName.c_str(),
150 g_usecTestElapsed*1e-6,
151 msg.m_bReliable ? "reliable" : "unreliable",
152 (long long)msg.m_nMsgNum,
153 msg.m_cbSize,
154 GetQueuedSendBytes() );
155 abort();
156 }
157 #if 0
158 else
159 TEST_Printf( "Send: %s %.3f %s message %lld, %d bytes (pending %d bytes)\n",
160 connection.m_sName.c_str(),
161 g_usecTestElapsed*1e-6,
162 msg.m_bReliable ? "reliable" : "unreliable",
163 (long long)msg.m_nMsgNum,
164 msg.m_cbSize,
165 GetQueuedSendBytes() );
166 #endif
167 }
168
169 void Send()
170 {

Callers 1

TestNetworkConditionsFunction · 0.80

Calls 6

SteamNetworkingUtilsFunction · 0.85
SteamNetworkingSocketsFunction · 0.85
TEST_PrintfFunction · 0.85
GetLocalTimestampMethod · 0.80
c_strMethod · 0.45

Tested by

no test coverage detected