Skip to content
Open
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
32 changes: 0 additions & 32 deletions src/FubarDev.FtpServer/FtpConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -932,38 +932,6 @@ public ConnectionClosingNetworkStreamReader(
_connectionClosedCts = connectionClosedCts;
}

/// <inheritdoc />
protected override async Task<int> ReadFromStreamAsync(byte[] buffer, int offset, int length, CancellationToken cancellationToken)
{
var readTask = Stream
.ReadAsync(buffer, offset, length, cancellationToken);

var tcs = new TaskCompletionSource<object?>();
using var registration = cancellationToken.Register(() => tcs.TrySetResult(null));
var resultTask = await Task.WhenAny(readTask, tcs.Task)
.ConfigureAwait(false);

if (cancellationToken.IsCancellationRequested)
{
Logger?.LogTrace("Cancelled through CancellationToken");
return 0;
}

if (resultTask != readTask)
{
Logger?.LogTrace("Cancelled through Task.Delay");
return 0;
}

#if NETSTANDARD1_3
return await readTask.ConfigureAwait(false);
#else
var result = readTask.Result;
readTask.Dispose();
return result;
#endif
}

/// <inheritdoc />
protected override async Task OnCloseAsync(Exception? exception, CancellationToken cancellationToken)
{
Expand Down