| 325 | |
| 326 | |
| 327 | bool cSocketThreads::cSocketThread::Start(void) |
| 328 | { |
| 329 | // Create the control socket listener |
| 330 | m_ControlSocket2 = cSocket::CreateSocket(cSocket::IPv4); |
| 331 | if (!m_ControlSocket2.IsValid()) |
| 332 | { |
| 333 | LOGERROR("Cannot create a Control socket for a cSocketThread (\"%s\"); continuing, but server may be unreachable from now on.", cSocket::GetLastErrorString().c_str()); |
| 334 | return false; |
| 335 | } |
| 336 | if (!m_ControlSocket2.BindToLocalhostIPv4(cSocket::ANY_PORT)) |
| 337 | { |
| 338 | LOGERROR("Cannot bind a Control socket for a cSocketThread (\"%s\"); continuing, but server may be unreachable from now on.", cSocket::GetLastErrorString().c_str()); |
| 339 | m_ControlSocket2.CloseSocket(); |
| 340 | return false; |
| 341 | } |
| 342 | if (!m_ControlSocket2.Listen(1)) |
| 343 | { |
| 344 | LOGERROR("Cannot listen on a Control socket for a cSocketThread (\"%s\"); continuing, but server may be unreachable from now on.", cSocket::GetLastErrorString().c_str()); |
| 345 | m_ControlSocket2.CloseSocket(); |
| 346 | return false; |
| 347 | } |
| 348 | if (m_ControlSocket2.GetPort() == 0) |
| 349 | { |
| 350 | LOGERROR("Cannot determine Control socket port (\"%s\"); conitnuing, but the server may be unreachable from now on.", cSocket::GetLastErrorString().c_str()); |
| 351 | m_ControlSocket2.CloseSocket(); |
| 352 | return false; |
| 353 | } |
| 354 | |
| 355 | // Start the thread |
| 356 | if (!super::Start()) |
| 357 | { |
| 358 | LOGERROR("Cannot start new cSocketThread"); |
| 359 | m_ControlSocket2.CloseSocket(); |
| 360 | return false; |
| 361 | } |
| 362 | |
| 363 | // Finish connecting the control socket by accepting connection from the thread's socket |
| 364 | cSocket tmp = m_ControlSocket2.AcceptIPv4(); |
| 365 | if (!tmp.IsValid()) |
| 366 | { |
| 367 | LOGERROR("Cannot link Control sockets for a cSocketThread (\"%s\"); continuing, but server may be unreachable from now on.", cSocket::GetLastErrorString().c_str()); |
| 368 | m_ControlSocket2.CloseSocket(); |
| 369 | return false; |
| 370 | } |
| 371 | m_ControlSocket2.CloseSocket(); |
| 372 | m_ControlSocket2 = tmp; |
| 373 | |
| 374 | return true; |
| 375 | } |
| 376 | |
| 377 | |
| 378 |
no test coverage detected