Skip to content

Commit c39e7c9

Browse files
author
Ahmad Noman Musleh
committed
Added another check to TCP read method
1 parent 566cc06 commit c39e7c9

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

src/OpenAPI.Net/OpenAPI.Net.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<PackageTags>cTrader, Open API, Spotware</PackageTags>
1010
<Description>A .NET RX library for Spotware Open API</Description>
1111
<PackageId>Spotware.OpenAPI.Net</PackageId>
12-
<Version>1.3.7-rc14</Version>
12+
<Version>1.3.7</Version>
1313
<Platforms>AnyCPU</Platforms>
1414
<Company>Spotware</Company>
1515
<Authors>Spotware</Authors>

src/OpenAPI.Net/OpenClient.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,8 @@ public void Dispose()
272272

273273
_messagesChannel.Writer.TryComplete();
274274

275+
_cancellationTokenSource.Dispose();
276+
275277
MessagesQueueCount = 0;
276278

277279
if (IsUsingWebSocket)
@@ -390,6 +392,8 @@ private async Task ReadTcp(CancellationToken cancellationToken)
390392
var count = lengthArray.Length - readBytes;
391393

392394
readBytes += await _sslStream.ReadAsync(lengthArray, readBytes, count, cancellationToken).ConfigureAwait(false);
395+
396+
if (readBytes == 0) new InvalidOperationException("Remote host closed the connection");
393397
}
394398
while (readBytes < lengthArray.Length);
395399

@@ -408,6 +412,8 @@ private async Task ReadTcp(CancellationToken cancellationToken)
408412
var count = data.Length - readBytes;
409413

410414
readBytes += await _sslStream.ReadAsync(data, readBytes, count, cancellationToken).ConfigureAwait(false);
415+
416+
if (readBytes == 0) new InvalidOperationException("Remote host closed the connection");
411417
}
412418
while (readBytes < length);
413419

@@ -416,7 +422,7 @@ private async Task ReadTcp(CancellationToken cancellationToken)
416422
OnNext(message);
417423
}
418424
}
419-
catch (Exception ex) when (ex is TaskCanceledException || ex is OperationCanceledException)
425+
catch (Exception ex) when (ex is OperationCanceledException)
420426
{
421427
}
422428
catch (Exception ex)

0 commit comments

Comments
 (0)