Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1325,6 +1325,13 @@ public void SendFile(string? fileName, ReadOnlySpan<byte> preBuffer, ReadOnlySpa

ThrowIfDisposed();

// SendFile is not supported on non-blocking sockets.
// ValidateBlockingMode() below checks for async mismatch; this checks explicit non-blocking.
if (!Blocking)
{
throw new InvalidOperationException(SR.net_sockets_blocking);
}

if (!IsConnectionOriented || !Connected)
{
throw new NotSupportedException(SR.net_notconnected);
Expand Down
12 changes: 12 additions & 0 deletions src/libraries/System.Net.Sockets/tests/FunctionalTests/SendFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,18 @@ public async Task NotConnected_ThrowsNotSupportedException()
await Assert.ThrowsAsync<NotSupportedException>(() => SendFileAsync(s, null, null, null, TransmitFileOptions.UseDefaultWorkerThread));
}

[Fact]
public void SendFile_NonBlockingSocket_ThrowsInvalidOperationException()
{
(Socket client, Socket server) = SocketTestExtensions.CreateConnectedSocketPair();
using (client)
using (server)
{
client.Blocking = false;
Assert.Throws<InvalidOperationException>(() => client.SendFile(null));
}
}

[Theory]
[InlineData(false)]
[InlineData(true)]
Expand Down
Loading