Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TcpClient.ConnectAsync(EndPoint) #44110

Merged
merged 3 commits into from
Nov 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/libraries/System.Net.Sockets/ref/System.Net.Sockets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -610,9 +610,11 @@ public void Connect(string hostname, int port) { }
public System.Threading.Tasks.Task ConnectAsync(System.Net.IPAddress address, int port) { throw null; }
public System.Threading.Tasks.Task ConnectAsync(System.Net.IPAddress[] addresses, int port) { throw null; }
public System.Threading.Tasks.Task ConnectAsync(string host, int port) { throw null; }
public System.Threading.Tasks.Task ConnectAsync(System.Net.IPEndPoint remoteEP) { throw null; }
public System.Threading.Tasks.ValueTask ConnectAsync(System.Net.IPAddress address, int port, System.Threading.CancellationToken cancellationToken) { throw null; }
public System.Threading.Tasks.ValueTask ConnectAsync(System.Net.IPAddress[] addresses, int port, System.Threading.CancellationToken cancellationToken) { throw null; }
public System.Threading.Tasks.ValueTask ConnectAsync(string host, int port, System.Threading.CancellationToken cancellationToken) { throw null; }
public System.Threading.Tasks.ValueTask ConnectAsync(System.Net.IPEndPoint remoteEP, System.Threading.CancellationToken cancellationToken) { throw null; }
public void Dispose() { }
protected virtual void Dispose(bool disposing) { }
public void EndConnect(System.IAsyncResult asyncResult) { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,14 @@ public Task ConnectAsync(string host, int port) =>
public Task ConnectAsync(IPAddress[] addresses, int port) =>
CompleteConnectAsync(Client.ConnectAsync(addresses, port));

/// <summary>
/// Connects the client to a remote TCP host using the specified endpoint as an asynchronous operation.
/// </summary>
/// <param name="remoteEP">The <see cref="IPEndPoint"/> to which you intend to connect.</param>
/// <returns>A task representing the asynchronous operation.</returns>
public Task ConnectAsync(IPEndPoint remoteEP) =>
CompleteConnectAsync(Client.ConnectAsync(remoteEP));

private async Task CompleteConnectAsync(Task task)
{
await task.ConfigureAwait(false);
Expand All @@ -283,6 +291,15 @@ public ValueTask ConnectAsync(string host, int port, CancellationToken cancellat
public ValueTask ConnectAsync(IPAddress[] addresses, int port, CancellationToken cancellationToken) =>
CompleteConnectAsync(Client.ConnectAsync(addresses, port, cancellationToken));

/// <summary>
/// Connects the client to a remote TCP host using the specified endpoint as an asynchronous operation.
/// </summary>
/// <param name="remoteEP">The <see cref="IPEndPoint"/> to which you intend to connect.</param>
/// <param name="cancellationToken">A cancellation token used to propagate notification that this operation should be canceled.</param>
/// <returns>A task representing the asynchronous operation.</returns>
public ValueTask ConnectAsync(IPEndPoint remoteEP, CancellationToken cancellationToken) =>
CompleteConnectAsync(Client.ConnectAsync(remoteEP, cancellationToken));
MartyIX marked this conversation as resolved.
Show resolved Hide resolved

private async ValueTask CompleteConnectAsync(ValueTask task)
{
await task.ConfigureAwait(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ public void Ctor_StringInt_ConnectsSuccessfully()
[InlineData(6)]
[InlineData(7)]
[InlineData(8)]
[InlineData(9)]
[InlineData(10)]
public async Task ConnectAsync_DnsEndPoint_Success(int mode)
{
using (var client = new DerivedTcpClient())
Expand Down Expand Up @@ -168,6 +170,14 @@ public async Task ConnectAsync_DnsEndPoint_Success(int mode)
await client.ConnectAsync(addresses[0], port, CancellationToken.None);
break;
case 8:
addresses = await Dns.GetHostAddressesAsync(host);
await client.ConnectAsync(new IPEndPoint(addresses[0], port));
break;
MartyIX marked this conversation as resolved.
Show resolved Hide resolved
case 9:
addresses = await Dns.GetHostAddressesAsync(host);
await client.ConnectAsync(new IPEndPoint(addresses[0], port), CancellationToken.None);
break;
case 10:
addresses = await Dns.GetHostAddressesAsync(host);
await client.ConnectAsync(addresses, port, CancellationToken.None);
break;
Expand Down