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

Socket.SendFileAsync based on SendPacketsAsync #52208

Merged
merged 8 commits into from
May 6, 2021

Conversation

gfoidl
Copy link
Member

@gfoidl gfoidl commented May 3, 2021

Contributes to #42591
It doesn't fix that issue as per #42591 (comment) cancellation is left out in order to unblock #43845

Also see #45132 (comment) (from a previous attempt).

/cc: @geoffkizer, @antonfirsov

@dotnet-issue-labeler
Copy link

Note regarding the new-api-needs-documentation label:

This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, to please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change.

@ghost
Copy link

ghost commented May 3, 2021

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

Issue Details

Contributes to #42591
It doesn't fix that issue as per #42591 (comment) cancellation is left out in order to unblock #43845

Also see #45132 (comment) (from a previous attempt).

/cc: @geoffkizer, @antonfirsov

Author: gfoidl
Assignees: -
Labels:

area-System.Net.Sockets, new-api-needs-documentation

Milestone: -

@@ -226,61 +226,5 @@ private void SendFileInternal(string? fileName, ReadOnlySpan<byte> preBuffer, Re
Send(postBuffer);
}
}

private async Task SendFileInternalAsync(FileStream? fileStream, byte[]? preBuffer, byte[]? postBuffer)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Unix-implementation is also based on SendPackets*, so Windows and Unix got unified here.
But I assume that now on Unix there are more allocations happening than before.

We can fix that once we base it on SAEA based version.

* from #42591 (comment)

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.

Copy link
Contributor

@geoffkizer geoffkizer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks!

@antonfirsov
Copy link
Member

/azp run runtime-libraries-coreclr outerloop

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@gfoidl
Copy link
Member Author

gfoidl commented May 5, 2021

The outerloop CI-failures are not related?

Work item System.Security.Cryptography.X509Certificates.Tests in job c6853abf-a82f-41ff-b559-9d403d117b2b has failed

@antonfirsov
Copy link
Member

Yeah, those are all unrelated. HTTP2 failures are known: #43877 #44352

Copy link
Member

@antonfirsov antonfirsov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks good, but I'm wondering why has been the API accepted in this form?

@@ -412,6 +412,8 @@ public partial class Socket : System.IDisposable
public void SendFile(string? fileName) { }
public void SendFile(string? fileName, byte[]? preBuffer, byte[]? postBuffer, System.Net.Sockets.TransmitFileOptions flags) { }
public void SendFile(string? fileName, System.ReadOnlySpan<byte> preBuffer, System.ReadOnlySpan<byte> postBuffer, System.Net.Sockets.TransmitFileOptions flags) { }
public System.Threading.Tasks.ValueTask SendFileAsync(string? fileName, System.ReadOnlyMemory<byte> preBuffer, System.ReadOnlyMemory<byte> postBuffer, System.Net.Sockets.TransmitFileOptions flags, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public System.Threading.Tasks.ValueTask SendFileAsync(string? fileName, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@geoffkizer do you know why did nullability change here during the API review (#42591 (comment) -> #42591 (comment)). Does anyone need socket.SendFile(null)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

socket.SendFile(null)

In this case only the pre- and post-buffer will be sent (if given). Whether anyone needs this or not I can't judge...but don't believe so.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not quite sure what is going on here...

Existing SendFile and BeginSendFile both have an overload that just takes string? fileName. So presumably we wanted SendFileAsync to match, which makes sense, even though SendFile(null) doesn't seem very useful.

However, the documentation has both this listed as string fileName, i.e. not nullable. E.g. here: https://docs.microsoft.com/en-us/dotnet/api/system.net.sockets.socket.beginsendfile?view=net-5.0

I would suggest we should be consistent with SendFile and BeginSendFile and allow null here. However we should also follow up on the doc issue, and we may want to end up making all of these non-null.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, see here: #42535

That explains the doc discrepancy -- that change was post-5.0, while the docs are based on 5.0.

Let's be consistent with #42535 here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So presumably we wanted SendFileAsync to match, which makes sense, even though SendFile(null) doesn't seem very useful.

That makes sense it's clear now, thanks!

@geoffkizer geoffkizer merged commit 3e6de7e into dotnet:main May 6, 2021
@gfoidl gfoidl deleted the sendfile-async-sendpackets branch May 13, 2021 16:40
@karelz karelz added this to the 6.0.0 milestone May 20, 2021
@geoffkizer geoffkizer mentioned this pull request May 27, 2021
14 tasks
@ghost ghost locked as resolved and limited conversation to collaborators Jun 19, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants