Socket.SendFile() is not supported on Windows, but the exceptions being thrown are not consistent. The first call throws SocketException, while the second attempt leads to NotSupportedException.
Repro
The twice=true case fails:
[Theory][InlineData(false)][InlineData(true)]publicvoidUDP_SendFile(booltwice){stringtempFile=Path.GetTempFileName();File.WriteAllBytes(tempFile,newbyte[128]);usingvarclient=newSocket(AddressFamily.InterNetwork,SocketType.Dgram,ProtocolType.Udp);usingvarlistener=newSocket(AddressFamily.InterNetwork,SocketType.Dgram,ProtocolType.Udp);listener.BindToAnonymousPort(IPAddress.Loopback);client.Connect(listener.LocalEndPoint);Assert.Throws<SocketException>(()=>client.SendFile(tempFile));if(twice){Assert.Throws<SocketException>(()=>client.SendFile(tempFile));// Throws NotSupportedException}}Edit (after discussion below)
On Linux the call does not fail. We should fail NotSupportedException for connectionless sockets on all OS-es in all cases.
Socket.SendFile()is not supported on Windows, but the exceptions being thrown are not consistent. The first call throwsSocketException, while the second attempt leads toNotSupportedException.Repro
The
twice=truecase fails:Edit (after discussion below)
On Linux the call does not fail. We should fail
NotSupportedExceptionfor connectionless sockets on all OS-es in all cases.