MCPcopy Create free account
hub / github.com/HumbleNet/HumbleNet / connectSocket

Function connectSocket

3rdparty/Amalgamate/juce_core_amalgam.cpp:7180–7239  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7178 }
7179
7180 static bool connectSocket (int volatile& handle,
7181 const bool isDatagram,
7182 struct addrinfo** const serverAddress,
7183 const String& hostName,
7184 const int portNumber,
7185 const int timeOutMillisecs) noexcept
7186 {
7187 struct addrinfo hints = { 0 };
7188 hints.ai_family = AF_UNSPEC;
7189 hints.ai_socktype = isDatagram ? SOCK_DGRAM : SOCK_STREAM;
7190 hints.ai_flags = AI_NUMERICSERV;
7191
7192 struct addrinfo* info = nullptr;
7193 if (getaddrinfo (hostName.toUTF8(), String (portNumber).toUTF8(), &hints, &info) != 0
7194 || info == nullptr)
7195 return false;
7196
7197 if (handle < 0)
7198 handle = (int) socket (info->ai_family, info->ai_socktype, 0);
7199
7200 if (handle < 0)
7201 {
7202 freeaddrinfo (info);
7203 return false;
7204 }
7205
7206 if (isDatagram)
7207 {
7208 if (*serverAddress != nullptr)
7209 freeaddrinfo (*serverAddress);
7210
7211 *serverAddress = info;
7212 return true;
7213 }
7214
7215 setSocketBlockingState (handle, false);
7216 const int result = ::connect (handle, info->ai_addr, (int) info->ai_addrlen);
7217 freeaddrinfo (info);
7218
7219 if (result < 0)
7220 {
7221 #if JUCE_WINDOWS
7222 if (result == SOCKET_ERROR && WSAGetLastError() == WSAEWOULDBLOCK)
7223 #else
7224 if (errno == EINPROGRESS)
7225 #endif
7226 {
7227 if (waitForReadiness (handle, false, timeOutMillisecs) != 1)
7228 {
7229 setSocketBlockingState (handle, true);
7230 return false;
7231 }
7232 }
7233 }
7234
7235 setSocketBlockingState (handle, true);
7236 resetSocketOptions (handle, false, false);
7237

Callers 1

connectMethod · 0.85

Calls 5

StringClass · 0.85
setSocketBlockingStateFunction · 0.85
waitForReadinessFunction · 0.85
resetSocketOptionsFunction · 0.85
toUTF8Method · 0.80

Tested by

no test coverage detected