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

Method AddClient

src/OSSupport/SocketThreads.cpp:41–69  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

39
40
41bool cSocketThreads::AddClient(const cSocket & a_Socket, cCallback * a_Client)
42{
43 // Add a (socket, client) pair for processing, data from a_Socket is to be sent to a_Client
44
45 // Try to add to existing threads:
46 cCSLock Lock(m_CS);
47 for (cSocketThreadList::iterator itr = m_Threads.begin(); itr != m_Threads.end(); ++itr)
48 {
49 if ((*itr)->IsValid() && (*itr)->HasEmptySlot())
50 {
51 (*itr)->AddClient(a_Socket, a_Client);
52 return true;
53 }
54 }
55
56 // No thread has free space, create a new one:
57 LOGD("Creating a new cSocketThread (currently have " SIZE_T_FMT ")", m_Threads.size());
58 cSocketThread * Thread = new cSocketThread(this);
59 if (!Thread->Start())
60 {
61 // There was an error launching the thread (but it was already logged along with the reason)
62 LOGERROR("A new cSocketThread failed to start");
63 delete Thread;
64 return false;
65 }
66 Thread->AddClient(a_Socket, a_Client);
67 m_Threads.push_back(Thread);
68 return true;
69}
70
71
72

Callers 1

OnConnectionAcceptedMethod · 0.45

Calls 11

LOGERRORFunction · 0.85
beginMethod · 0.80
endMethod · 0.80
HasEmptySlotMethod · 0.80
sizeMethod · 0.80
SetNonBlockingMethod · 0.80
clearMethod · 0.80
IsValidMethod · 0.45
StartMethod · 0.45
SendMethod · 0.45

Tested by

no test coverage detected