Fix HTTP connect on linux (need to ignore failed connections in the select)

This commit is contained in:
Henrik Rydgård 2023-09-17 17:13:18 +02:00
parent b6515ef1e6
commit 0421607c00

View file

@ -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) {