-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Consider adding Socket Send/ReceiveAsync overloads that elide SocketFlags argument #43934
Comments
Tagging subscribers to this area: @dotnet/ncl |
Agreed, this will simplify call sites and improve readability. I think we should go for an API proposal. Is it just an overlook that these overloads were missing from the original proposal for |
I don't think there was a practical reason, aside from just keeping the API surface minimal. |
This seems reasonable to me, especially considering we have already approved UDP APIs with these overloads. |
Triage: Let's add them from consistency reasons. |
@antonfirsov Do you want to put together the actual API proposal? |
@geoffkizer edited the opening post, hope all overloads are included. |
The new overloads for SendToAsync, ReceiveFromAsync, and ReceiveMessageFromAsync in #33418 aren't included above. I think we should include them for completeness, even though they have technically been approved already. |
Yeah. Also, we should make sure to merge this API back into #33418 once approved. |
Ok, will add tomorrow, thanks for checking! |
Done, PTAL |
Looks good |
According to #43901, we should move the proposed methods to the |
Is it possible to use default arguments ( For most overloads this could be used. Some of them have the |
My understanding is that isn't possible to do, though I'm not sure why. @terrajobst would know. |
I do wonder if we should wait a bit here until we figure out scatter/gather APIs. If we have new and improved scatter/gather APIs, we should only add overloads for those. |
namespace System.Net.Sockets
{
// Existing overloads in comments
partial class Socket
{
// public Task<int> ReceiveAsync(ArraySegment<byte> buffer, SocketFlags socketFlags);
public Task<int> ReceiveAsync(ArraySegment<byte> buffer);
// public Task<int> ReceiveAsync(IList<ArraySegment<byte>> buffers, SocketFlags socketFlags);
public Task<int> ReceiveAsync(IList<ArraySegment<byte>> buffers);
// public ValueTask<int> ReceiveAsync(Memory<byte> buffer, SocketFlags socketFlags, CancellationToken cancellationToken = default(CancellationToken));
public ValueTask<int> ReceiveAsync(Memory<byte> buffer, CancellationToken cancellationToken = default(CancellationToken));
// public Task<SocketReceiveFromResult> ReceiveFromAsync(ArraySegment<byte> buffer, SocketFlags socketFlags, EndPoint remoteEndPoint);
public Task<SocketReceiveFromResult> ReceiveFromAsync(ArraySegment<byte> buffer, EndPoint remoteEndPoint);
// public Task<SocketReceiveMessageFromResult> ReceiveMessageFromAsync(ArraySegment<byte> buffer, SocketFlags socketFlags, EndPoint remoteEndPoint);
public Task<SocketReceiveMessageFromResult> ReceiveMessageFromAsync(ArraySegment<byte> buffer, EndPoint remoteEndPoint);
// public Task<int> SendAsync(ArraySegment<byte> buffer, SocketFlags socketFlags);
public Task<int> SendAsync(ArraySegment<byte> buffer);
// public Task<int> SendAsync(IList<ArraySegment<byte>> buffers, SocketFlags socketFlags);
public Task<int> SendAsync(IList<ArraySegment<byte>> buffers);
// public ValueTask<int> SendAsync(ReadOnlyMemory<byte> buffer, SocketFlags socketFlags, CancellationToken cancellationToken = default(CancellationToken));
public ValueTask<int> SendAsync(ReadOnlyMemory<byte> buffer, CancellationToken cancellationToken = default(CancellationToken));
// public Task<int> SendToAsync(ArraySegment<byte> buffer, SocketFlags socketFlags, EndPoint remoteEP);
public Task<int> SendToAsync(ArraySegment<byte> buffer, EndPoint remoteEP);
// public ValueTask<int> SendToAsync(ReadOnlyMemory<byte> buffer, SocketFlags socketFlags, EndPoint remoteEP, CancellationToken cancellationToken = default);
public ValueTask<int> SendToAsync(ReadOnlyMemory<byte> buffer, EndPoint remoteEP, CancellationToken cancellationToken = default);
// public ValueTask<SocketReceiveFromResult> ReceiveFromAsync(Memory<byte> buffer, SocketFlags socketFlags, EndPoint remoteEP, CancellationToken cancellationToken = default);
public ValueTask<SocketReceiveFromResult> ReceiveFromAsync(Memory<byte> buffer, EndPoint remoteEP, CancellationToken cancellationToken = default);
// public ValueTask<SocketReceiveMessageFromResult> ReceiveMessageFromAsync(Memory<byte> buffer, SocketFlags socketFlags, EndPoint remoteEP, CancellationToken cancellationToken = default);
public ValueTask<SocketReceiveMessageFromResult> ReceiveMessageFromAsync(Memory<byte> buffer, EndPoint remoteEP, CancellationToken cancellationToken = default);
/*** DOUBLE CHECK THAT THIS ONE IS OK, SINCE IT IS NO LONGER "RETURNING" DATA ***/
// public int ReceiveMessageFrom(Span<byte> buffer, ref SocketFlags socketFlags, ref EndPoint remoteEP, out IPPacketInformation ipPacketInformation);
public int ReceiveMessageFrom(Span<byte> buffer, ref EndPoint remoteEP, out IPPacketInformation ipPacketInformation);
}
[EditorBrowsable(EditorBrowsableState.Never)]
partial class SocketTaskExtensions
{
}
} |
// public ValueTask<int> ReceiveAsync(Memory<byte> buffer, SocketFlags socketFlags, CancellationToken cancellationToken = default(CancellationToken)); There is no runtime/src/libraries/System.Net.Sockets/src/System/Net/Sockets/Socket.Tasks.cs Lines 297 to 298 in 24971b0
Should the new overload have |
Same for 8th method
|
As long as it's there in the reference assembly declarations, it should work fine:
However we should have probably assigned the defaults in the implementation declarations too for clarity and consistency. |
* Elide SocketFlags in Socket API Fix #43934 * Fix SocketAsyncEventArgs tests * Cosmetics * Elide SocketFlags in tests * Comments
Background and Motivation
The sync methods for Send, Receive, SendTo, and ReceiveFrom all have overloads that don't take a SocketFlags argument. This argument is rarely used.
The Task-based async methods don't have these overloads. We actually approved overloads without SocketFlags for SendTo and ReceiveFrom in #938, but these haven't been implemented yet, and it doesn't really make sense to implement them just for SendTo and ReceiveFrom.
Proposed API
Additions to existing overloads
Additions to #938
Consider: addition to #43933
This is not an async API but probably worth to add.
@scalablecory @wfurt @antonfirsov @stephentoub Thoughts?
The text was updated successfully, but these errors were encountered: