| 379 | |
| 380 | |
| 381 | void 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 |
nothing calls this directly
no test coverage detected