1
0
mirror of https://github.com/JKorf/CryptoExchange.Net.git synced 2026-08-16 19:03:01 +00:00

Added additional checks to not send/expect data when socket is not connected

This commit is contained in:
Jkorf
2021-10-08 13:16:20 +02:00
parent 0bad51d775
commit a969e99e05
4 changed files with 157 additions and 2 deletions
+10 -1
View File
@@ -452,6 +452,9 @@ namespace CryptoExchange.Net.Sockets
{
if (Authenticated)
{
if (!Socket.IsOpen)
return false;
// If we reconnected a authenticated connection we need to re-authenticate
var authResult = await socketClient.AuthenticateSocketAsync(this).ConfigureAwait(false);
if (!authResult)
@@ -475,6 +478,9 @@ namespace CryptoExchange.Net.Sockets
var taskList = new List<Task>();
foreach (var subscription in subscriptionList.Skip(i).Take(socketClient.MaxConcurrentResubscriptionsPerSocket))
{
if (!Socket.IsOpen)
continue;
var task = socketClient.SubscribeAndWaitAsync(this, subscription.Request!, subscription).ContinueWith(t =>
{
if (!t.Result)
@@ -484,7 +490,7 @@ namespace CryptoExchange.Net.Sockets
}
await Task.WhenAll(taskList).ConfigureAwait(false);
if (!success)
if (!success || !Socket.IsOpen)
return false;
}
@@ -499,6 +505,9 @@ namespace CryptoExchange.Net.Sockets
internal async Task<CallResult<bool>> ResubscribeAsync(SocketSubscription socketSubscription)
{
if (!Socket.IsOpen)
return new CallResult<bool>(false, new UnknownError("Socket is not connected"));
return await socketClient.SubscribeAndWaitAsync(this, socketSubscription.Request!, socketSubscription).ConfigureAwait(false);
}