Skip to content

Commit

Permalink
Address PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
stephentoub committed Sep 22, 2020
1 parent 0a548ad commit ce02c8f
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions src/libraries/System.Net.Sockets/tests/FunctionalTests/SendFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Versioning;
using System.Threading;
using System.Threading.Tasks;

Expand Down Expand Up @@ -106,9 +105,15 @@ public void NotConnected_ThrowsException()
}

[Theory]
[InlineData(false)]
[InlineData(true)]
public async Task SendFile_Empty_SucceedsSendingNothing(bool useAsync)
[InlineData(false, false, false)]
[InlineData(false, false, true)]
[InlineData(false, true, false)]
[InlineData(false, true, true)]
[InlineData(true, false, false)]
[InlineData(true, false, true)]
[InlineData(true, true, false)]
[InlineData(true, true, true)]
public async Task SendFile_NoFile_Succeeds(bool useAsync, bool usePreBuffer, bool usePostBuffer)
{
using var client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
using var listener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
Expand All @@ -128,18 +133,26 @@ public async Task SendFile_Empty_SucceedsSendingNothing(bool useAsync)
}
Assert.Equal(0, client.Available);

byte[] preBuffer = usePreBuffer ? new byte[1] : null;
byte[] postBuffer = usePostBuffer ? new byte[1] : null;
int bytesExpected = (usePreBuffer ? 1 : 0) + (usePostBuffer ? 1 : 0);

if (useAsync)
{
await Task.Factory.FromAsync((c, s) => server.BeginSendFile(null, null, null, TransmitFileOptions.UseDefaultWorkerThread, c, s), server.EndSendFile, null);
await Task.Factory.FromAsync((c, s) => server.BeginSendFile(null, preBuffer, postBuffer, TransmitFileOptions.UseDefaultWorkerThread, c, s), server.EndSendFile, null);
}
else
{
server.SendFile(null, null, null, TransmitFileOptions.UseDefaultWorkerThread);
server.SendFile(null, preBuffer, postBuffer, TransmitFileOptions.UseDefaultWorkerThread);
}
Assert.Equal(0, client.Available);

server.Send(new byte[1]);
Assert.Equal(1, client.Receive(new byte[2]));
byte[] receiveBuffer = new byte[1];
for (int i = 0; i < bytesExpected; i++)
{
Assert.Equal(1, client.Receive(receiveBuffer));
}

Assert.Equal(0, client.Available);
}

[ActiveIssue("https://github.com/dotnet/runtime/issues/42534", TestPlatforms.Windows)]
Expand Down

0 comments on commit ce02c8f

Please sign in to comment.