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

Fix a few Socket.SendFile issues #42535

Merged
merged 2 commits into from
Sep 23, 2020
Merged

Conversation

stephentoub
Copy link
Member

@stephentoub stephentoub commented Sep 21, 2020

  • The string argument in the single-argument overload should be nullable.
  • All overloads on Windows should allow a null file path, but they've been throwing an exception
  • On Linux, data was silently truncated when sending a file larger than int.MaxValue with BeginSendFile.

Fixes #42530
Fixes #42529
Fixes #41906

@ghost
Copy link

ghost commented Sep 21, 2020

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

Copy link
Member

@wfurt wfurt left a comment

Choose a reason for hiding this comment

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

LGTM with notes @geoffkizer already made.
the manual DangerousAddRef seems unfortunate.

- The string argument in the single-argument overload should be nullable.
- All overloads on Windows should allow a null file path, but they've been throwing an exception
- On Linux, data was silently truncated when sending a file larger than int.MaxValue with BeginSendFile.
@stephentoub stephentoub merged commit 2734a38 into dotnet:master Sep 23, 2020
@stephentoub stephentoub deleted the fixsendfile branch September 23, 2020 13:23
@@ -383,7 +383,7 @@ public partial class Socket : System.IDisposable
public int Send(System.ReadOnlySpan<byte> buffer, System.Net.Sockets.SocketFlags socketFlags) { throw null; }
public int Send(System.ReadOnlySpan<byte> buffer, System.Net.Sockets.SocketFlags socketFlags, out System.Net.Sockets.SocketError errorCode) { throw null; }
public bool SendAsync(System.Net.Sockets.SocketAsyncEventArgs e) { throw null; }
public void SendFile(string fileName) { }
public void SendFile(string? fileName) { }
Copy link
Member

Choose a reason for hiding this comment

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

I thought we decided in #32675 (comment) that this should be non-null. Calling SendFile(null) won't do anything, so the assumption is you should pass in a fileName.

Copy link
Member

Choose a reason for hiding this comment

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

If we are moving this to be nullable, to be consistent, we should annotate the BeginSendFile overload as nullable as well.

Copy link
Member Author

Choose a reason for hiding this comment

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

We did, but issuing a warning doesn't actually solve any problems here, and it leads to an inconsistency with the other overload. It's not harmful to pass null, it's always been allowed on .NET Framework, etc., so we may as well gain the consistency, avoid potential noisy warnings, and allow 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.

If we are moving this to be nullable, to be consistent, we should annotate the BeginSendFile overload as nullable as well.

I thought I did. I'll fix it.

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 docs are also explicit about null being allowed.)

@ghost ghost locked as resolved and limited conversation to collaborators Dec 7, 2020
@karelz karelz added this to the 6.0.0 milestone Jan 26, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
7 participants