diff --git a/Common/Net/HTTPClient.cpp b/Common/Net/HTTPClient.cpp index 5a8e12f7ee..449251100b 100644 --- a/Common/Net/HTTPClient.cpp +++ b/Common/Net/HTTPClient.cpp @@ -117,7 +117,13 @@ bool Connection::Connect(int maxTries, double timeout, bool *cancelConnect) { fd_util::SetNonBlocking(sock, true); // Start trying to connect (async with timeout.) - connect(sock, possible->ai_addr, (int)possible->ai_addrlen); + errno = 0; + if (connect(sock, possible->ai_addr, (int)possible->ai_addrlen) < 0) { + if (errno != EINPROGRESS) { + ERROR_LOG(HTTP, "connect(%d) call failed (%d: %s)", sock, errno, strerror(errno)); + continue; + } + } sockets.push_back(sock); FD_SET(sock, &fds); if (maxfd < sock + 1) { @@ -125,6 +131,11 @@ bool Connection::Connect(int maxTries, double timeout, bool *cancelConnect) { } } + if (sockets.empty()) { + ERROR_LOG(HTTP, "No resolved address would connect!"); + // TODO: What do we do here? + } + int selectResult = 0; long timeoutHalfSeconds = floor(2 * timeout); while (timeoutHalfSeconds >= 0 && selectResult == 0) {