Skip to content

Commit

Permalink
Added separate cancellation tokens for TCP read operations
Browse files Browse the repository at this point in the history
  • Loading branch information
Ahmad Noman Musleh committed Jan 18, 2022
1 parent 6bce3c1 commit fc1f813
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/OpenAPI.Net/OpenAPI.Net.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<PackageTags>cTrader, Open API, Spotware</PackageTags>
<Description>A .NET RX library for Spotware Open API</Description>
<PackageId>Spotware.OpenAPI.Net</PackageId>
<Version>1.3.7-rc0</Version>
<Version>1.3.7-rc1</Version>
<Platforms>AnyCPU</Platforms>
<Company>Spotware</Company>
<Authors>Spotware</Authors>
Expand Down
8 changes: 6 additions & 2 deletions src/OpenAPI.Net/OpenClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,9 @@ private async Task ReadTcp(CancellationToken cancellationToken)
{
var count = lengthArray.Length - readBytes;

readBytes += await _sslStream.ReadAsync(lengthArray, readBytes, count, cancellationToken).ConfigureAwait(false);
var cancellationTokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(20));

readBytes += await _sslStream.ReadAsync(lengthArray, readBytes, count, cancellationTokenSource.Token).ConfigureAwait(false);
}
while (readBytes < lengthArray.Length);

Expand All @@ -405,7 +407,9 @@ private async Task ReadTcp(CancellationToken cancellationToken)
{
var count = data.Length - readBytes;

readBytes += await _sslStream.ReadAsync(data, readBytes, count, cancellationToken).ConfigureAwait(false);
var cancellationTokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(20));

readBytes += await _sslStream.ReadAsync(data, readBytes, count, cancellationTokenSource.Token).ConfigureAwait(false);
}
while (readBytes < length);

Expand Down

0 comments on commit fc1f813

Please sign in to comment.