MCPcopy Create free account
hub / github.com/CalcProgrammer1/OpenRGB / ConnectionThreadFunction

Method ConnectionThreadFunction

NetworkClient.cpp:190–314  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

188}
189
190void NetworkClient::ConnectionThreadFunction()
191{
192 unsigned int requested_controllers;
193
194 //This thread manages the connection to the server
195 while(client_active == true)
196 {
197 if(server_connected == false)
198 {
199 //Connect to server and reconnect if the connection is lost
200 server_initialized = false;
201
202 //Try to connect to server
203 if(port.tcp_client_connect() == true)
204 {
205 client_sock = port.sock;
206 printf( "Connected to server\n" );
207
208 //Server is now connected
209 server_connected = true;
210
211 //Start the listener thread
212 ListenThread = new std::thread(&NetworkClient::ListenThreadFunction, this);
213
214 //Server is not initialized
215 server_initialized = false;
216
217 /*-------------------------------------------------*\
218 | Client info has changed, call the callbacks |
219 \*-------------------------------------------------*/
220 ClientInfoChanged();
221 }
222 else
223 {
224 printf( "Connection attempt failed\n" );
225 }
226 }
227
228 if(server_initialized == false && server_connected == true)
229 {
230 unsigned int timeout_counter = 0;
231 requested_controllers = 0;
232 server_controller_count = 0;
233 server_controller_count_received = false;
234 server_protocol_version_received = false;
235
236 //Wait for server to connect
237 std::this_thread::sleep_for(100ms);
238
239 //Request protocol version
240 SendRequest_ProtocolVersion();
241
242 //Wait up to 1s for protocol version reply
243
244 while(!server_protocol_version_received)
245 {
246 std::this_thread::sleep_for(5ms);
247

Callers

nothing calls this directly

Calls 3

tcp_client_connectMethod · 0.80
sizeMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected