Unified to throw NotSupportedException when SendFile() for connectionless sockets...
authorrhirano0715 <104247605+rhirano0715@users.noreply.github.com>
Wed, 9 Aug 2023 12:19:38 +0000 (21:19 +0900)
committerGitHub <noreply@github.com>
Wed, 9 Aug 2023 12:19:38 +0000 (05:19 -0700)
commit24f151365fe1a1795775f2ad0287aba8f14f40d0
tree6e5ca43834450730ddb8328705340c38dafde6f9
parentb35572540e0904c6a23dc5466f73c361ed877dc1
Unified to throw NotSupportedException when SendFile() for connectionless sockets (#87108)

* Unified to throw NotSupportedException when SendFile() for connectionless 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

* Change to throws `NotSupportedException` if `!IsConnectionOriented` or `!Connected`.

Before:.

    Throws `NotSupportedException` on UDP.

After:

    Throws `NotSupportedException` if `!IsConnectionOriented` or `!Connected`.

* Changed test case `UdpConnection_ThrowsException` to run regardless of platform.

* Update src/libraries/System.Net.Sockets/src/System/Net/Sockets/Socket.Tasks.cs

Co-authored-by: Karel Zikmund <karelz@microsoft.com>
---------

Co-authored-by: Karel Zikmund <karelz@microsoft.com>
src/libraries/System.Net.Sockets/src/System/Net/Sockets/Socket.Tasks.cs
src/libraries/System.Net.Sockets/src/System/Net/Sockets/Socket.cs
src/libraries/System.Net.Sockets/tests/FunctionalTests/SendFile.cs