Skip to content

Commit

Permalink
Fixing usage with net8.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mconnew committed Oct 6, 2023
1 parent 0cbb21d commit 4479347
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 10 deletions.
4 changes: 2 additions & 2 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
</PropertyGroup>

<PropertyGroup>
<ScenarioTestTargetFrameworks>net6.0;net7.0</ScenarioTestTargetFrameworks>
<UnitTestTargetFrameworks>net6.0;net7.0</UnitTestTargetFrameworks>
<ScenarioTestTargetFrameworks>net6.0;net7.0;net8.0</ScenarioTestTargetFrameworks>
<UnitTestTargetFrameworks>net6.0;net7.0;net8.0</UnitTestTargetFrameworks>
<!-- This is the target framework version of the built tests picked up to send to Helix -->
<XUnitPublishTargetFramework>net6.0</XUnitPublishTargetFramework>
</PropertyGroup>
Expand Down
3 changes: 2 additions & 1 deletion global.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"runtimes": {
"dotnet": [
"3.1.5",
"6.0.5"
"6.0.22",
"7.0.11"
]
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,11 @@ public override void Write(byte[] buffer, int offset, int count)

public override async Task<int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
{
if (count == 0)
{
return 0;
}

var tcs = new TaskCompletionSource<int>(this);
AsyncCompletionResult asyncCompletionResult = Connection.BeginRead(0, Math.Min(count, Connection.AsyncReadBufferSize),
TimeoutHelper.FromMilliseconds(ReadTimeout), s_onReadComplete, tcs);
Expand Down Expand Up @@ -777,7 +782,7 @@ internal static void ValidateBufferBounds(int bufferSize, int offset, int size)
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(offset), offset, SR.Format(SR.OffsetExceedsBufferSize, bufferSize)));
}

if (size <= 0)
if (size < 0)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(size), size, SR.ValueMustBePositive));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ public override async Task<int> ReadAsync(byte[] buffer, int offset, int count,
{
return 0;
}

int returnValue = await base.ReadAsync(buffer, offset, count, cancellationToken);
if (returnValue == 0)
if (count != 0 && returnValue == 0)
{
ReceivedEof();
}
Expand All @@ -49,7 +50,7 @@ public override int Read(byte[] buffer, int offset, int count)
return 0;
}
int returnValue = base.Read(buffer, offset, count);
if (returnValue == 0)
if (count != 0 && returnValue == 0)
{
ReceivedEof();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ public override void Flush()

public override int Read(byte[] buffer, int offset, int count)
{
if (count == 0)
{
return 0;
}

try
{
return ReadAsync(buffer, offset, count, CancellationToken.None).GetAwaiter().GetResult();
Expand All @@ -55,19 +60,24 @@ public override async Task<int> ReadAsync(byte[] buffer, int offset, int count,
{
if (buffer == null)
{
throw new ArgumentNullException("buffer");
throw new ArgumentNullException(nameof(buffer));
}
if (offset < 0 || offset > buffer.Length)
{
throw new ArgumentOutOfRangeException("offset");
throw new ArgumentOutOfRangeException(nameof(offset));
}
if (count <= 0 || count > buffer.Length - offset)
if (count < 0 || count > buffer.Length - offset)
{
throw new ArgumentOutOfRangeException("count");
throw new ArgumentOutOfRangeException(nameof(count));
}

cancellationToken.ThrowIfCancellationRequested();

if (count == 0)
{
return 0;
}

// _dataAvail must be set before the disposed check to avoid a race condition
// when Dispose is called just after the _disposed check which would result in
// ReadAsync never completing.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,11 @@ private void DecodeSize(byte[] buffer, ref int offset, ref int size)

private int ReadCore(byte[] buffer, int offset, int count)
{
if (count == 0)
{
return 0;
}

int bytesRead = -1;
try
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -979,6 +979,12 @@ public virtual AsyncCompletionResult BeginRead(int offset, int size, TimeSpan ti
private AsyncCompletionResult BeginReadCore(int offset, int size, TimeSpan timeout,
Action<object> callback, object state)
{
if (size == 0)
{
_asyncReadSize = 0;
return AsyncCompletionResult.Completed;
}

bool abortRead = true;

lock (ThisLock)
Expand Down

0 comments on commit 4479347

Please sign in to comment.