* libwget/dns.c (getaddrinfo_merging, resolve): Code cleanup.
* libwget/net.c (wget_tcp_connect): Connect first, then set socket to async.
Connecting asynchronously prevented wget2 to fallback to the next IP address
of a host when a connect error occurred.
Reported at https://github.com/rockdaboot/wget2/issues/325
The resolve() function only returned SOCK_STREAM (TCP) sockets. We lift
that limitation here, such that it will now return all socket types
available in the system, both SOCK_STREAM and SOCK_DGRAM. And we let the
calling function choose the socket type they want. We make this change
to adapt for the upcoming QUIC code, which works entirely over UDP.
* libwget/dns.c (resolve): Remove SOCK_STREAM constraint, return all
kinds of sock types available.
* libwget/net.c (wget_tcp_connect): select SOCK_STREAM socket types
only
(tcp_connect): new function to establish TCP connections.
* libwget/net.h (struct wget_tcp_st): New member remote_port.
* libwget/net.c (wget_tcp_connect): Set tcp->remote_port.
* libwget/ssl_gnutls.c (struct session_context): New member port,
(wget_ssl_open): Set ctx->port,
(verify_certificate_callback): Use ctx->port for DANE verification.
* libwget/net.c: New function print_error(),
new function print_error_host(),
(wget_tcp_connect): Use new functions for error messages,
(wget_tcp_read): Likewise,
(wget_tcp_write): Likewise.
* libwget/dns.c (wget_dns_resolve): 'rc' was set but not used.
* libwget/http.c (wget_http_get_response_cb): 'rc' was set but not used.
* libwget/net.c (wget_tcp_connect): 'rc' was set but not used.
* libwget/ssl_gnutls.c (send_ocsp_request): 'rc' was set but not used.
* include/wget/wget.h: Likewise
* libwget/net.c: Likewise
* libwget/init.c (wget_global_init): Fix param type to wget_tcp_set_tcp_fastopen()
* src/wget_options.h (struct config): Change type of tcp_fastopen to bool
* include/wget/wget.h: Rewrite parts of the DNS / DNS caching API
* libwget/dns.c: Likewise
* libwget/dns_cache.c: Likewise
* libwget/init.c (wget_global_init): Amend WGET_DNS_CACHING
* libwget/net.c: Cleanup and amend for the new API
* libwget/net.h: Cleanup
* src/options.c: Use DNS caching instance if caching is requested
* docs/Makefile.am: Add libwget-dns.3 man page
* examples/batch_loader.c: Remove call to wget_tcp_set_dns_timeout()
* examples/check_url_types.c: Use wget_dns_set_timeout()
* include/wget/wget.h: Add wget_dns_ API
* libwget/Makefile.am: Add dns.c
* libwget/dns.c: New file
* libwget/init.c: Use wget_dns_set_caching()
* libwget/net.c: Remove DNS functions
* libwget/net.h (wget_tcp_st): Add dns member
* po/POTFILES.in: Add libwget/dns.c
* src/options.c: Use new DNS API
* src/stats.c: Add some checks
* src/stats_dns.c: Use wget_dns_get_stats()
* libwget/net.c: #define TCP_FASTOPEN_LINUX_411,
(_set_socket_options): Set TCP_FASTOPEN_CONNECT socket option,
(wget_tcp_connect): Add code for Linux 4.11+
The glibc async functions turned out to be unstable and
error-prone. They also use threads to implement timeouts.
If we need DNS timeouts and/or async DNS lookups, we should
have a look at external resolver libraries.