From b01eed2042fafa34d0ea2f1ea61ed23be2d4196c Mon Sep 17 00:00:00 2001 From: Wizou Date: Fri, 1 Oct 2021 02:44:56 +0200 Subject: [PATCH] DC disconnect bug fix --- src/Client.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Client.cs b/src/Client.cs index 75cf69d..f74fe93 100644 --- a/src/Client.cs +++ b/src/Client.cs @@ -26,7 +26,7 @@ namespace WTelegram public Config TLConfig { get; private set; } public int MaxAutoReconnects { get; set; } = 5; // number of automatic reconnections on connection/reactor failure public bool IsMainDC => (_dcSession?.DataCenter?.id ?? 0) == _session.MainDC; - public bool Connected => _tcpClient?.Connected ?? false; + public bool Disconnected => _tcpClient != null && !(_tcpClient.Client?.Connected ?? false); private readonly Func _config; private readonly int _apiId; @@ -134,7 +134,6 @@ namespace WTelegram _sendSemaphore = new(0); _reactorTask = null; _tcpClient?.Dispose(); - _tcpClient = null; _connecting = null; if (resetSessions) { @@ -252,7 +251,7 @@ namespace WTelegram lock (_session) { altSession = GetOrCreateDCSession(dcId, _dcSession.DataCenter.flags | (media_only ? DcOption.Flags.media_only : 0)); - if (!altSession.Client.Connected) { altSession.Client.Dispose(); altSession.Client = null; } + if (altSession.Client?.Disconnected ?? false) { altSession.Client.Dispose(); altSession.Client = null; } altSession.Client ??= new Client(this, altSession); } Helpers.Log(2, $"Requested connection to DC {dcId}...");