MCPcopy Create free account
hub / github.com/RomanKubiak/ctrlr / connectSocket

Function connectSocket

JUCE/modules/juce_core/network/juce_Socket.cpp:368–428  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

366 }
367
368 static bool connectSocket (std::atomic<int>& handle,
369 CriticalSection& readLock,
370 const String& hostName,
371 int portNumber,
372 int timeOutMillisecs) noexcept
373 {
374 bool success = false;
375
376 if (auto* info = getAddressInfo (false, hostName, portNumber))
377 {
378 for (auto* i = info; i != nullptr; i = i->ai_next)
379 {
380 auto newHandle = socket (i->ai_family, i->ai_socktype, 0);
381
382 if (newHandle != invalidSocket)
383 {
384 setSocketBlockingState (newHandle, false);
385 auto result = ::connect (newHandle, i->ai_addr, (socklen_t) i->ai_addrlen);
386 success = (result >= 0);
387
388 if (! success)
389 {
390 #if JUCE_WINDOWS
391 if (result == SOCKET_ERROR && WSAGetLastError() == WSAEWOULDBLOCK)
392 #else
393 if (errno == EINPROGRESS)
394 #endif
395 {
396 std::atomic<int> cvHandle { (int) newHandle };
397
398 if (waitForReadiness (cvHandle, readLock, false, timeOutMillisecs) == 1)
399 success = true;
400 }
401 }
402
403 if (success)
404 {
405 handle = (int) newHandle;
406 break;
407 }
408
409 #if JUCE_WINDOWS
410 closesocket (newHandle);
411 #else
412 ::close (newHandle);
413 #endif
414 }
415 }
416
417 freeaddrinfo (info);
418
419 if (success)
420 {
421 auto h = (SocketHandle) handle.load();
422 setSocketBlockingState (h, true);
423 resetSocketOptions (h, false, false);
424 }
425 }

Callers 1

connectMethod · 0.85

Calls 7

getAddressInfoFunction · 0.85
setSocketBlockingStateFunction · 0.85
connectFunction · 0.85
waitForReadinessFunction · 0.85
resetSocketOptionsFunction · 0.85
closeFunction · 0.50
loadMethod · 0.45

Tested by

no test coverage detected