dotnet/runtime

Missing Socket APIs mega-issue

Open

#43,935 opened on 2020年10月28日

GitHub で見る
 (8 comments) (2 reactions) (0 assignees)C# (5,445 forks)batch import
area-System.Net.Socketsenhancementhelp wanted

Repository metrics

Stars
 (17,886 stars)
PR merge metrics
 (平均マージ 12d 11h) (30d で 661 merged PRs)

説明

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);
  • SendToAsync, ReceiveFromAsync, and ReceiveMessageFromAsync need Memory and CancellationToken support -- see #33418. (Note, this should probably wait until #41502 is completed.)
	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

  • Move Task-based methods from SocketTaskExtensions to Socket -- see #43901
  • Memory support for SendPacketElements -- see #45267
  • Consider overloads for Task-based methods that remove #SocketFlags argument -- see #43934
  • Remove Socket finalizer and ensure SafeSocketHandle finalization works correctly -- see #43383
  • New APIs for zero-allocation connectionless sockets -- see #30797

コントリビューターガイド