MCPcopy Create free account
hub / github.com/cuberite/cuberite / Execute

Method Execute

src/OSSupport/SocketThreads.cpp:381–420  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

379
380
381void cSocketThreads::cSocketThread::Execute(void)
382{
383 // Connect the "client" part of the Control socket:
384 m_ControlSocket1 = cSocket::CreateSocket(cSocket::IPv4);
385 ASSERT(m_ControlSocket2.GetPort() != 0); // We checked in the Start() method, but let's be sure
386 if (!m_ControlSocket1.ConnectToLocalhostIPv4(m_ControlSocket2.GetPort()))
387 {
388 LOGERROR("Cannot connect Control sockets for a cSocketThread (\"%s\"); continuing, but the server may be unreachable from now on.", cSocket::GetLastErrorString().c_str());
389 m_ControlSocket2.CloseSocket();
390 return;
391 }
392
393 // The main thread loop:
394 while (!m_ShouldTerminate)
395 {
396 // Read outgoing data from the clients:
397 QueueOutgoingData();
398
399 // Put sockets into the sets
400 fd_set fdRead;
401 fd_set fdWrite;
402 cSocket::xSocket Highest = m_ControlSocket1.GetSocket();
403 PrepareSets(&fdRead, &fdWrite, Highest);
404
405 // Wait for the sockets:
406 timeval Timeout;
407 Timeout.tv_sec = 5;
408 Timeout.tv_usec = 0;
409 if (select(Highest + 1, &fdRead, &fdWrite, NULL, &Timeout) == -1)
410 {
411 LOG("select() call failed in cSocketThread: \"%s\"", cSocket::GetLastErrorString().c_str());
412 continue;
413 }
414
415 // Perform the IO:
416 ReadFromSockets(&fdRead);
417 WriteToSockets(&fdWrite);
418 CleanUpShutSockets();
419 } // while (!mShouldTerminate)
420}
421
422
423

Callers

nothing calls this directly

Calls 7

LOGERRORFunction · 0.85
LOGFunction · 0.85
GetPortMethod · 0.80
c_strMethod · 0.80
GetSocketMethod · 0.80
CloseSocketMethod · 0.45

Tested by

no test coverage detected