-
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
Unified to throw NotSupportedException when SendFile() for connectionless sockets #87108
Conversation
…less sockets The issue was that the Socket.SendFile() threw inconsistent exceptions when the platform was Windows and the protocol was UDP. The first call would throw a SocketException, while the second call would throw a NotSupportedException. With this commit, SendFile() will consistently throw NotSupportException on all platforms when the protocol is UDP. Fix #47472
Tagging subscribers to this area: @dotnet/ncl Issue DetailsThe issue was that the Socket.SendFile() threw inconsistent exceptions when the platform was Windows and the protocol was UDP. The first call would throw a SocketException, while the second call would throw a NotSupportedException. With this commit, SendFile() will consistently throw NotSupportException on all platforms when the protocol is UDP. Fix #47472
|
@dotnet-policy-service agree |
@antonfirsov ping, can you please take a look? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the long delay!
if (_protocolType == ProtocolType.Udp) | ||
{ | ||
throw new NotSupportedException(SR.net_notconnected); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that BeginSendFile
calls into SendFileAsync
, this check is redundant.
if (usePreAndPostbufferOverload) | ||
{ | ||
ex = await Assert.ThrowsAsync<SocketException>(() => SendFileAsync(client, tempFile.Path, Array.Empty<byte>(), Array.Empty<byte>(), TransmitFileOptions.UseDefaultWorkerThread)); | ||
await Assert.ThrowsAsync<NotSupportedException>(() => SendFileAsync(client, tempFile.Path, Array.Empty<byte>(), Array.Empty<byte>(), TransmitFileOptions.UseDefaultWorkerThread)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test case should not be [PlatformSpecific(TestPlatforms.Windows)]
anymore.
if (_protocolType == ProtocolType.Udp) | ||
{ | ||
throw new NotSupportedException(SR.net_notconnected); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't the check if (!IsConnectionOriented)
do the job already? In #47472 I only tested the sync overload.
if (_protocolType == ProtocolType.Udp) | ||
{ | ||
throw new NotSupportedException(SR.net_notconnected); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The async variant checks for if (!IsConnectionOriented)
while the sync version checks (!Connected)
. I think that - instead of limiting the error case explicitly to UDP - we should consolidate these checks, throwing in case of (!IsConnectionOriented || !Connected)
.
@rhirano0715 will you have time to look at the CR feedback from @antonfirsov please? |
…r `!Connected`. Before:. Throws `NotSupportedException` on UDP. After: Throws `NotSupportedException` if `!IsConnectionOriented` or `!Connected`.
@karelz @antonfirsov |
src/libraries/System.Net.Sockets/src/System/Net/Sockets/Socket.Tasks.cs
Outdated
Show resolved
Hide resolved
….Tasks.cs Co-authored-by: Karel Zikmund <[email protected]>
/azp run runtime |
/azp run runtime-extra-platforms |
Azure Pipelines successfully started running 1 pipeline(s). |
1 similar comment
Azure Pipelines successfully started running 1 pipeline(s). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks, and sorry for the slow response. Started some extra CI runs just in case.
/azp run runtime-extra-platforms |
Azure Pipelines successfully started running 1 pipeline(s). |
The issue was that the Socket.SendFile() threw inconsistent exceptions when the platform was Windows and the protocol was UDP. The first call would throw a SocketException, while the second call would throw a NotSupportedException.
With this commit, SendFile() will consistently throw NotSupportException on all platforms when the protocol is UDP.
Fix #47472