Description
Address Family specific name resolution
These APIs would return addresses only within a specified address family. This allows for improved perf if you are only interested in a specific address family, as otherwise DNS requires sending two separate requests for A and AAAA records, and waiting for both to come back before returning.
This is needed to implement RFC 8305 "Happy Eyeballs" in Socket.Connect
. Part of Happy Eyeballs is doing IPv4 and IPv6 name resolution in parallel and then coordinating concurrent Connect() calls that may start without waiting for both DNS resolution calls to return. See #861 for more.
Cancellation and ValueTask
This also adds overloads for existing async APIs, with added CancellationToken
and returning ValueTask
. Brought into this super-issue from dotnet/corefx#40586.
Post review note: ValueTask
reverted for usability purposes as OS doesn't support meaningful synchronous completion.
Proposed APIs
class System.Net.Dns
{
// AddressFamily versions would all just set the ai_family hint in getaddrinfo.
// existing: public static IPAddress[] GetHostAddresses(string hostNameOrAddress);
public static IPAddress[] GetHostAddresses(string hostNameOrAddress, AddressFamily family);
// existing: public static Task<IPAddress[]> GetHostAddressesAsync(string hostNameOrAddress);
public static Task<IPAddress[]> GetHostAddressesAsync(string hostNameOrAddress, CancellationToken cancellationToken);
public static Task<IPAddress[]> GetHostAddressesAsync(string hostNameOrAddress, AddressFamily family, CancellationToken cancellationToken = default);
// existing: public static IPHostEntry GetHostEntry(string hostNameOrAddress);
public static IPHostEntry GetHostEntry(string hostNameOrAddress, AddressFamily family);
// existing: public static Task<IPHostEntry> GetHostEntryAsync(string hostNameOrAddress);
public static Task<IPHostEntry> GetHostEntryAsync(string hostNameOrAddress, CancellationToken cancellationToken);
public static Task<IPHostEntry> GetHostEntryAsync(string hostNameOrAddress, AddressFamily family, CancellationToken cancellationToken = default);
// existing: public static Task<IPHostEntry> GetHostEntryAsync(IPAddress address);
public static Task<IPHostEntry> GetHostEntryAsync(IPAddress address, CancellationToken cancellationToken);
}