lib/fetch: add happy eyeballs connect algorithm (RFC6555/RFC8305)

Connect to the addresses from `getaddrinfo(3)`,
alternating between address family,
starting with ipv6 and wait `fetchConnDelay`
between each connection attempt.

If a connection is established within the attempts,
use this connection and close all others.

If `connect(3)` returns `ENETUNREACH`, don't attempt more
connections with the failing address family.

If there are no more addresses to attempt,
wait for `fetchConnTimeout` and return the first established
connection.

If no connection was established within the timeouts,
close all sockets and return -1 and set errno to
`ETIMEDOUT`.
This commit is contained in:
Duncaen
2019-03-18 17:47:28 +01:00
parent 291faddf8c
commit 9f52a7837f
3 changed files with 207 additions and 18 deletions

View File

@ -173,6 +173,12 @@ extern char fetchLastErrString[MAXERRSTRING];
/* I/O timeout */
extern int fetchTimeout;
/* Connect timeout */
extern int fetchConnTimeout;
/* Connect attempt delay */
extern int fetchConnDelay;
/* Restart interrupted syscalls */
extern volatile int fetchRestartCalls;