MCPcopy Create free account
hub / github.com/defold/defold / NewSocket

Function NewSocket

engine/dlib/src/dlib/message.cpp:172–217  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

170 } g_ContextDestroyer;
171
172 Result NewSocket(const char* name, HSocket* socket)
173 {
174 if (dmAtomicGet32(&g_ContextDestroyer.m_Deleted))
175 {
176 return RESULT_SOCKET_OUT_OF_RESOURCES;
177 }
178
179 if (name == 0x0 || *name == 0 || strchr(name, '#') != 0x0 || strchr(name, ':') != 0x0)
180 {
181 return RESULT_INVALID_SOCKET_NAME;
182 }
183
184 dmhash_t name_hash = dmHashString64(name);
185
186 DM_SPINLOCK_SCOPED_LOCK(g_MessageSpinlock);
187
188 if (g_MessageContext == 0)
189 {
190 g_MessageContext = Create(MAX_SOCKETS);
191 }
192
193 if (g_MessageContext->m_Sockets.Full())
194 {
195 return RESULT_SOCKET_OUT_OF_RESOURCES;
196 }
197
198 HSocket tmp;
199 if (GetSocketNoLock(name_hash, &tmp) == RESULT_OK)
200 {
201 return RESULT_SOCKET_EXISTS;
202 }
203
204 MessageSocket s;
205 s.m_RefCount = 1;
206 s.m_Header = 0;
207 s.m_Tail = 0;
208 s.m_NameHash = name_hash;
209 s.m_Name = strdup(name);
210 s.m_Mutex = dmMutex::New();
211 s.m_Condition = dmConditionVariable::New();
212
213 g_MessageContext->m_Sockets.Put(name_hash, s);
214 *socket = name_hash;
215
216 return RESULT_OK;
217 }
218
219 static void DisposeSocket(MessageSocket* s)
220 {

Callers 15

AttachCollectionFunction · 0.85
SetUpMethod · 0.85
SetUpMethod · 0.85
SetUpMethod · 0.85
NewFunction · 0.85
TEST_FFunction · 0.85
SetUpMethod · 0.85
TEST_FFunction · 0.85
LogInitializeFunction · 0.85
TESTFunction · 0.85
engine.cppFile · 0.85
NewContext3DFunction · 0.85

Calls 6

dmAtomicGet32Function · 0.85
GetSocketNoLockFunction · 0.85
CreateFunction · 0.70
NewFunction · 0.70
FullMethod · 0.45
PutMethod · 0.45

Tested by 11

SetUpMethod · 0.68
SetUpMethod · 0.68
SetUpMethod · 0.68
TEST_FFunction · 0.68
SetUpMethod · 0.68
TEST_FFunction · 0.68
TESTFunction · 0.68
TEST_FFunction · 0.68
SetUpMethod · 0.68
TEST_FFunction · 0.68
SetUpMethod · 0.68