mirror of
https://github.com/JKorf/CryptoExchange.Net
synced 2025-06-07 07:56:12 +00:00
Socket connection improvements on reconnect
This commit is contained in:
parent
e62786a70f
commit
b90a0a71e9
@ -194,11 +194,16 @@ namespace CryptoExchange.Net.Sockets
|
||||
try
|
||||
{
|
||||
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)
|
||||
{
|
||||
_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;
|
||||
}
|
||||
|
||||
@ -386,10 +391,13 @@ namespace CryptoExchange.Net.Sockets
|
||||
if (_disposed)
|
||||
return;
|
||||
|
||||
if (_ctsSource?.IsCancellationRequested == false)
|
||||
_ctsSource.Cancel();
|
||||
|
||||
_logger.SocketDisposing(Id);
|
||||
_disposed = true;
|
||||
_socket.Dispose();
|
||||
_ctsSource.Dispose();
|
||||
_ctsSource?.Dispose();
|
||||
_logger.SocketDisposed(Id);
|
||||
}
|
||||
|
||||
|
@ -714,6 +714,12 @@ namespace CryptoExchange.Net.Sockets
|
||||
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);
|
||||
try
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user