-
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
Add Task-based async API for Socket.SendFile #42591
Comments
Tagging subscribers to this area: @dotnet/ncl |
namespace System.Net.Sockets
{
public partial class Socket
{
// Existing APM APIs
// public IAsyncResult BeginSendFile(string fileName, AsyncCallback? callback, object? state);
// public IAsyncResult BeginSendFile(string? fileName, byte[]? preBuffer, byte[]? postBuffer, TransmitFileOptions flags, AsyncCallback? callback, object? state);
public ValueTask SendFileAsync(string? fileName, CancellationToken cancellationToken = default);
public ValueTask SendFileAsync(string? fileName, ReadOnlyMemory<byte> preBuffer, ReadOnlyMemory<byte> postBuffer, TransmitFileOptions flags, CancellationToken cancellationToken = default);
}
} |
@stephentoub can you assign this to me? |
Sure :-) Thanks. Cancellation will be the trickiest part; the rest should be very straightforward. |
Note to myself: don't forget to update the ref-assemblies. |
Can the windows-version actually be cancelled (in a nice way)? The code goes down to runtime/src/libraries/System.Net.Sockets/src/System/Net/Sockets/SocketPal.Windows.cs Lines 1150 to 1152 in f025f53
For the unix-version existing code can be reused (after tweaking a little bit). |
Has cancelling on windows be done via runtime/src/libraries/System.Net.Sockets/src/System/Net/Sockets/SocketAsyncEventArgs.Windows.cs Line 102 in f025f53
Interop.Kernel32.CancelIoEx )?
(Now I understand why you wrote tricky). |
Yup
😉 |
I got lost a bit in all the issue around sockets and especially for SendPacketsAsync...need to revive the branches. For Unix it's quite straight-forward including cancellation. For Windows we talked about basing it on SendPacketsAsync which can't be canceled (at least last time I checked). There's #48477 but I don't know the state of that issue. Also SendPacketsAsync has quite some allocations that I'll prepare a PR based on SendPackets, as it's easier to move forward. We can optimize that later on. Can this issue / PR wait for Mon / Tue next week? (need to find a fix a 🐞 in my code, so can look into this over the weekend) |
Yeah, it's not urgent, I just want to make sure we can get this in for 6.0.
If we base it on SendPacketsAsync, this would work for both Windows and Unix, which is preferred -- we don't want to have more platform-specific code here if we can avoid it. SendPacketsAsync can't be cancelled, but the way we have done cancellation for other Task-based APIs is to have an internal version that does support cancellation. You should see this pattern for other APIs like Send, Receive, etc. That said, cancellation support here is a bit ugly currently. I would be fine with punting cancellation support for a first PR -- we need to address cancellation for a couple different operations anyway, including Accept (see #33418) and Disconnect (see #51452). It probably makes sense to tackle all of these at once. @antonfirsov thoughts? |
I'm fine getting this in with I'm wondering if we should also publish |
We could consider it, but I don't think it's a priority. It doesn't add anything that SendPacketsAsync can't do. |
Triage: Cancellation implementation is missing. Fine to move to Future. |
Background and Motivation
We have an APM version of this and a SocketAsyncEventArgs version, but no Task-based version.
Current APM:
Proposed API
The text was updated successfully, but these errors were encountered: