Skip to content

Commit 4eab1df

Browse files
committed
Add IP address support to HappyEyeballs
1 parent 6501df3 commit 4eab1df

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

StartSch/HappyEyeballs.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,20 @@ public static async ValueTask<Stream> SocketsHttpHandlerConnectCallback(
2121
SocketsHttpConnectionContext ctx,
2222
CancellationToken ct)
2323
{
24-
if (IPAddress.TryParse(ctx.DnsEndPoint.Host, out IPAddress? _))
25-
throw new NotImplementedException();
24+
if (IPAddress.TryParse(ctx.DnsEndPoint.Host, out IPAddress? ipAddress))
25+
{
26+
Socket ipSocket = new(ipAddress.AddressFamily, SocketType.Stream, ProtocolType.Tcp) { NoDelay = true };
27+
try
28+
{
29+
await ipSocket.ConnectAsync(ipAddress, ctx.DnsEndPoint.Port, ct);
30+
return new NetworkStream(ipSocket, true);
31+
}
32+
catch
33+
{
34+
ipSocket.Dispose();
35+
throw;
36+
}
37+
}
2638

2739
DnsEndPoint dnsEndPoint = ctx.DnsEndPoint;
2840

0 commit comments

Comments
 (0)