mirror of
https://github.com/JKorf/CryptoExchange.Net.git
synced 2026-08-21 13:23:07 +00:00
Socket connection improvements on reconnect
This commit is contained in:
@@ -194,11 +194,16 @@ namespace CryptoExchange.Net.Sockets
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
using CancellationTokenSource tcs = new(TimeSpan.FromSeconds(10));
|
using CancellationTokenSource tcs = new(TimeSpan.FromSeconds(10));
|
||||||
await _socket.ConnectAsync(Uri, tcs.Token).ConfigureAwait(false);
|
using var linked = CancellationTokenSource.CreateLinkedTokenSource(tcs.Token, _ctsSource.Token);
|
||||||
|
await _socket.ConnectAsync(Uri, linked.Token).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
_logger.SocketConnectionFailed(Id, e.Message, e);
|
if (!_ctsSource.IsCancellationRequested)
|
||||||
|
{
|
||||||
|
// if _ctsSource was canceled this was already logged
|
||||||
|
_logger.SocketConnectionFailed(Id, e.Message, e);
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -386,10 +391,13 @@ namespace CryptoExchange.Net.Sockets
|
|||||||
if (_disposed)
|
if (_disposed)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (_ctsSource?.IsCancellationRequested == false)
|
||||||
|
_ctsSource.Cancel();
|
||||||
|
|
||||||
_logger.SocketDisposing(Id);
|
_logger.SocketDisposing(Id);
|
||||||
_disposed = true;
|
_disposed = true;
|
||||||
_socket.Dispose();
|
_socket.Dispose();
|
||||||
_ctsSource.Dispose();
|
_ctsSource?.Dispose();
|
||||||
_logger.SocketDisposed(Id);
|
_logger.SocketDisposed(Id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -714,6 +714,12 @@ namespace CryptoExchange.Net.Sockets
|
|||||||
return new CallResult(new InvalidOperationError(info));
|
return new CallResult(new InvalidOperationError(info));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!_socket.IsOpen)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("[Sckt {SocketId}] msg {RequestId} - Failed to send, socket no longer open", SocketId, requestId);
|
||||||
|
return new CallResult(new WebError("Failed to send message, socket no longer open"));
|
||||||
|
}
|
||||||
|
|
||||||
_logger.SendingData(SocketId, requestId, data);
|
_logger.SendingData(SocketId, requestId, data);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user