-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Add CancellationToken overloads to Socket.ConnectAsync and Socket.AcceptAsync #921
Comments
FWIW, they were actually added in .NET Core 2.1, but the tokens were only checked prior to initiating the call. dotnet/corefx#36516 plumbed them all the way down. |
ah ok. I took a look what is possible with current APIs: |
Does this include |
Those are not included (currently). Adding them to |
TODO: Looks also into other APIs on Sockets as mentioned in #19592 |
public static ValueTask<Socket> AcceptAsync (this Socket socket, Socket acceptSocket, CancellationToken cancellationToken); This one will throw PNSE on non-Windows: runtime/src/libraries/System.Net.Sockets/src/System/Net/Sockets/Socket.Unix.cs Lines 106 to 110 in 35fe82c
|
Slightly unrelated: Does this mean AcceptTcpClientAsync (as a layer on top of Socket) won't work unless we use Windows? What is the alternative? |
@xsacha only the overloads that pass in an existing socket as an |
class SocketTaskExtensions
{
public static ValueTask ConnectAsync (this Socket socket, EndPoint remoteEP, CancellationToken cancellationToken);
public static ValueTask ConnectAsync (this Socket socket, IPAddress address, int port, CancellationToken cancellationToken);
public static ValueTask ConnectAsync (this Socket socket, IPAddress[] addresses, int port, CancellationToken cancellationToken);
public static ValueTask ConnectAsync (this Socket socket, string host, int port, CancellationToken cancellationToken);
public static ValueTask<Socket> AcceptAsync (this Socket socket, CancellationToken cancellationToken);
public static ValueTask<Socket> AcceptAsync (this Socket socket, Socket acceptSocket, CancellationToken cancellationToken);
// existing methods:
// public static Task ConnectAsync (this Socket socket, EndPoint remoteEP);
// public static Task ConnectAsync (this Socket socket, IPAddress address, int port);
// public static Task ConnectAsync (this Socket socket, IPAddress[] addresses, int port);
// public static Task ConnectAsync (this Socket socket, string host, int port);
// public static Task<Socket> AcceptAsync (this Socket socket);
// public static Task<Socket> AcceptAsync (this Socket socket, Socket acceptSocket);
}
class Socket
{
public static void CancelAcceptAsync(SocketAsyncEventArgs e);
// existing methods:
// public bool AcceptAsync (SocketAsyncEventArgs e);
// public bool ConnectAsync (SocketAsyncEventArgs e);
// public static void CancelConnectAsync (SocketAsyncEventArgs e);
}
class TcpClient
{
public ValueTask ConnectAsync (string host, int port, CancellationToken cancellationToken);
public ValueTask ConnectAsync (IPAddress address, int port, CancellationToken cancellationToken);
public ValueTask ConnectAsync (IPAddress[] addresses, int port, CancellationToken cancellationToken);
// existing methods:
// public Task ConnectAsync (string host, int port);
// public Task ConnectAsync (IPAddress address, int port);
// public Task ConnectAsync (IPAddress[] addresses, int port);
}
class TcpListener
{
public ValueTask<Socket> AcceptSocketAsync (CancellationToken cancellationToken);
public ValueTask<TcpClient> AcceptTcpClientAsync (CancellationToken cancellationToken);
// existing methods:
// public Task<Socket> AcceptSocketAsync ();
// public Task<TcpClient> AcceptTcpClientAsync ();
} |
Closing for mega-issue #33418. |
CancellationTokens were added to SendAsync and ReceiveAsync in PR dotnet/corefx#36516
This for adding overloads to ConnectAsync and AcceptAsync:
CC @stephentoub
The text was updated successfully, but these errors were encountered: