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

Method Start

src/OSSupport/SocketThreads.cpp:327–375  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

325
326
327bool 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

Callers 1

AddClientMethod · 0.45

Calls 8

LOGERRORFunction · 0.85
c_strMethod · 0.80
BindToLocalhostIPv4Method · 0.80
ListenMethod · 0.80
GetPortMethod · 0.80
AcceptIPv4Method · 0.80
IsValidMethod · 0.45
CloseSocketMethod · 0.45

Tested by

no test coverage detected