aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDag-Erling Smørgrav <des@FreeBSD.org>2026-06-29 15:53:54 +0000
committerDag-Erling Smørgrav <des@FreeBSD.org>2026-06-29 15:53:54 +0000
commit667ef98c29f94c34d06f5ff1d5d32c99a04f6082 (patch)
treea9c1c9abae855dd7472019c92430719eae10a78d
parent15ee1fc07457b5fb7e1b027d18afc4ffc9aa56b2 (diff)
Revert "libfetch: Apply timeout to connection attempts"
This reverts commit d53af4112273f7b234a1cdd6694b3a7ca0aae0eb.
-rw-r--r--lib/libfetch/common.c47
1 files changed, 6 insertions, 41 deletions
diff --git a/lib/libfetch/common.c b/lib/libfetch/common.c
index d1a897b98827..c1888a1518a0 100644
--- a/lib/libfetch/common.c
+++ b/lib/libfetch/common.c
@@ -593,13 +593,10 @@ fetch_socks5_getenv(char **host, int *port)
conn_t *
fetch_connect(const char *host, int port, int af, int verbose)
{
- struct timeval now, timeout, delta;
- struct pollfd pfd;
struct addrinfo *cais = NULL, *sais = NULL, *cai, *sai;
const char *bindaddr;
conn_t *conn = NULL;
int err = 0, sd = -1;
- int deltams;
char *sockshost;
int socksport;
@@ -657,47 +654,15 @@ fetch_connect(const char *host, int port, int af, int verbose)
fetch_verbose("failed to bind to %s", bindaddr);
goto syserr;
}
- /* make the socket non-blocking */
- (void)fcntl(sd, F_SETFL, O_NONBLOCK);
- /* start the clock */
- if (fetchTimeout > 0) {
- gettimeofday(&timeout, NULL);
- timeout.tv_sec += fetchTimeout;
- deltams = fetchTimeout * 1000;
- }
/* attempt to connect to server address */
- if ((err = connect(sd, sai->ai_addr, sai->ai_addrlen)) == 0)
+ while ((err = connect(sd, sai->ai_addr, sai->ai_addrlen)) < 0) {
+ if (errno == EINTR && fetchRestartCalls)
+ continue;
break;
- /* wait for connection */
- if (errno == EINPROGRESS) {
- deltams = INFTIM;
- pfd.fd = sd;
- pfd.events = POLLOUT;
- for (;;) {
- /* wait for something to happen */
- if (poll(&pfd, 1, deltams) >= 0)
- break;
- if (errno == EINTR && !fetchRestartCalls)
- break;
- /* check the clock */
- if (fetchTimeout > 0) {
- gettimeofday(&now, NULL);
- if (!timercmp(&timeout, &now, >)) {
- errno = ETIMEDOUT;
- pfd.revents = POLLERR;
- break;
- }
- timersub(&timeout, &now, &delta);
- deltams = delta.tv_sec * 1000 +
- delta.tv_usec / 1000;
- }
- }
- if (pfd.revents == POLLOUT) {
- /* connection established */
- err = 0;
- break;
- }
}
+ /* success? */
+ if (err == 0)
+ break;
/* clean up before next attempt */
close(sd);
sd = -1;