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

Missing Socket APIs mega-issue #43935

Open
10 of 14 tasks
geoffkizer opened this issue Oct 28, 2020 · 8 comments
Open
10 of 14 tasks

Missing Socket APIs mega-issue #43935

geoffkizer opened this issue Oct 28, 2020 · 8 comments
Assignees
Labels
area-System.Net.Sockets enhancement Product code improvement that does NOT require public API changes/additions help wanted [up-for-grabs] Good issue for external contributors
Milestone

Comments

@geoffkizer
Copy link
Contributor

geoffkizer commented Oct 28, 2020

We still have a few gaps in our Socket APIs where we are missing support for Task, Span/Memory, or CancellationToken.

This is a mega-issue to track all remaining work here for 6.0.

Async Socket APIs:

	public static ValueTask<Socket> AcceptAsync (this Socket socket, CancellationToken cancellationToken);
	public static ValueTask<Socket> AcceptAsync (this Socket socket, Socket acceptSocket, CancellationToken cancellationToken);
	public static ValueTask<int> SendToAsync(this Socket socket, ReadOnlyMemory<byte> buffer, SocketFlags socketFlags, EndPoint remoteEP, CancellationToken cancellationToken = null);
	public static ValueTask<SocketReceiveFromResult> ReceiveFromAsync(this Socket socket, Memory<byte> buffer, SocketFlags socketFlags, EndPoint remoteEP, CancellationToken cancellationToken = null);
	public static ValueTask<SocketReceiveMessageFromResult> ReceiveMessageFromAsync(this Socket socket, Memory<byte> buffer, SocketFlags socketFlags, EndPoint remoteEP, CancellationToken cancellationToken = null);
        public ValueTask SendFileAsync(string? fileName, CancellationToken cancellationToken = default);
        public ValueTask SendFileAsync(string? fileName, ReadOnlyMemory<byte> preBuffer, ReadOnlyMemory<byte> postBuffer, TransmitFileOptions flags, CancellationToken cancellationToken = default);
        public static ValueTask DisconnectAsync(this Socket socket, bool reuseSocket, CancellationToken cancellationToken=default);

Sync Socket APIs:

	public int SendTo(ReadOnlySpan<byte> buffer, EndPoint remoteEP);
	public int SendTo(ReadOnlySpan<byte> buffer, SocketFlags socketFlags, EndPoint remoteEP);
	public int ReceiveFrom(Span<byte> buffer, ref EndPoint remoteEP);
	public int ReceiveFrom(Span<byte> buffer, SocketFlags socketFlags, ref EndPoint remoteEP);
        public int ReceiveMessageFrom(Span<byte> buffer, ref System.Net.Sockets.SocketFlags socketFlags, ref System.Net.EndPoint remoteEP, out System.Net.Sockets.IPPacketInformation ipPacketInformation);
        public void SendFile(string fileName, ReadOnlySpan<byte> preBuffer, ReadOnlySpan<byte> postBuffer, TransmitFileOptions flags);

Async TcpListener APIs:

	public ValueTask<Socket> AcceptSocketAsync (CancellationToken cancellationToken);
	public ValueTask<TcpClient> AcceptTcpClientAsync (CancellationToken cancellationToken);

Async TcpClient APIs:

namespace System.Net.Sockets
{
    public class TcpClient : IDisposable
    {
        public Task ConnectAsync(IPEndPoint remoteEP);
        public ValueTask ConnectAsync(IPEndPoint remoteEP, CancellationToken cancellationToken);
    }
}

UdpClient APIs:

public class UdpClient
{
    public int Send(ReadOnlySpan<byte> datagram);
    public int Send(ReadOnlySpan<byte> datagram, IPEndPoint endPoint);
    public int Send(ReadOnlySpan<byte> datagram, string hostname, int port);
    public ValueTask<int> SendAsync(ReadOnlyMemory<byte> datagram, CancellationToken cancellationToken);
    public ValueTask<int> SendAsync(ReadOnlyMemory<byte> datagram, IPEndPoint endPoint, CancellationToken cancellationToken);
    public ValueTask<UdpReceiveResult> ReceiveAsync(CancellationToken cancellationToken);
}

Related issues

@ghost
Copy link

ghost commented Oct 28, 2020

Tagging subscribers to this area: @dotnet/ncl
See info in area-owners.md if you want to be subscribed.

@Dotnet-GitSync-Bot Dotnet-GitSync-Bot added the untriaged New issue has not been triaged by the area owner label Oct 28, 2020
@GSPP
Copy link

GSPP commented Oct 29, 2020

Is it common policy to not provide CancellationToken support for synchronous APIs? It seems just as useful to have it for sync as it is for async.

@antonfirsov
Copy link
Member

@GSPP for sockets, it's not possible to implement reliable cancellation of synchronous calls in a cross-platform way. From #42686 (comment):

Note that POSIX does not specify a way to abort on-going synchronous calls. The implementation is relying on OS specifics which work well on Linux, and less well on some other OSes. For best cross-platform behaviour applications should avoid using Dispose to abort on-going operations.

(#42686 is a typical issue around this problem)

@geoffkizer
Copy link
Contributor Author

In general we don't provide CancellationToken support for sync APIs.

@karelz karelz added api-suggestion Early API idea and discussion, it is NOT ready for implementation enhancement Product code improvement that does NOT require public API changes/additions and removed untriaged New issue has not been triaged by the area owner api-suggestion Early API idea and discussion, it is NOT ready for implementation labels Oct 29, 2020
@karelz
Copy link
Member

karelz commented Oct 29, 2020

Triage: The APIs should be approved in the spin offs, not in this issue - this one is just tracking all the work.

Note: Some of the sub-issues are simple, so good for up-for-grabs.

@karelz karelz added the help wanted [up-for-grabs] Good issue for external contributors label Oct 29, 2020
@antonfirsov
Copy link
Member

SendToAsync, ReceiveFromAsync, and ReceiveMessageFromAsync need Memory and CancellationToken support -- see #33148.

@geoffkizer you meant #938 I guess.

@geoffkizer
Copy link
Contributor Author

@geoffkizer you meant #938 I guess.

Actually, I meant #33418, but that links to #938 too. Thanks for catching, fixed now.

@wfurt
Copy link
Member

wfurt commented Dec 15, 2022

triage: we should revisit what is missing and close the mega issue

@wfurt wfurt modified the milestones: Future, 8.0.0 Dec 15, 2022
@wfurt wfurt modified the milestones: 8.0.0, Future Jun 7, 2023
@karelz karelz modified the milestones: Future, 9.0.0 Jul 18, 2023
@antonfirsov antonfirsov modified the milestones: 9.0.0, 10.0.0 Jun 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-System.Net.Sockets enhancement Product code improvement that does NOT require public API changes/additions help wanted [up-for-grabs] Good issue for external contributors
Projects
None yet
Development

No branches or pull requests

6 participants