Skip to content

Commit

Permalink
simplify CanUseConnectEx
Browse files Browse the repository at this point in the history
  • Loading branch information
antonfirsov committed Mar 19, 2020
1 parent a01760f commit 5196b01
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2090,12 +2090,9 @@ public IAsyncResult BeginConnect(EndPoint remoteEP, AsyncCallback? callback, obj

private bool CanUseConnectEx(EndPoint remoteEP)
{
return (_socketType == SocketType.Stream) &&
(_rightEndPoint != null || remoteEP.GetType() == typeof(IPEndPoint));
return _socketType == SocketType.Stream && remoteEP is IPEndPoint;
}



internal IAsyncResult UnsafeBeginConnect(EndPoint remoteEP, AsyncCallback? callback, object? state, bool flowContext = false)
{
if (CanUseConnectEx(remoteEP))
Expand Down
16 changes: 16 additions & 0 deletions src/libraries/System.Net.Sockets/tests/FunctionalTests/Connect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,22 @@ public async Task Connect_Udp_Success(IPAddress listenAt)
Assert.True(client.Connected);
}

[Theory]
[MemberData(nameof(Loopbacks))]
public async Task Connect_Dns_Success(IPAddress listenAt)
{
int port;
using (SocketTestServer.SocketTestServerFactory(SocketImplementationType.Async, listenAt, out port))
{
using (Socket client = new Socket(listenAt.AddressFamily, SocketType.Stream, ProtocolType.Tcp))
{
Task connectTask = ConnectAsync(client, new DnsEndPoint("localhost", port));
await connectTask;
Assert.True(client.Connected);
}
}
}

[OuterLoop]
[Theory]
[MemberData(nameof(Loopbacks))]
Expand Down

0 comments on commit 5196b01

Please sign in to comment.