diff options
author | George Hazan <george.hazan@gmail.com> | 2023-08-17 14:29:10 +0300 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2023-08-17 14:29:10 +0300 |
commit | 55ac1013817d7b1759e73635c27c02d5a9776390 (patch) | |
tree | 3b56c7b0dc45fc4270442d6b4cddf34389f6f2d3 /protocols/Tox/src/tox_connection.cpp | |
parent | 2e9d5f15f17ab2f57ee534d32bb0ef110e4e8892 (diff) |
fixes #3611 (Tox plugin makes the whole UI hang)
Diffstat (limited to 'protocols/Tox/src/tox_connection.cpp')
-rw-r--r-- | protocols/Tox/src/tox_connection.cpp | 83 |
1 files changed, 36 insertions, 47 deletions
diff --git a/protocols/Tox/src/tox_connection.cpp b/protocols/Tox/src/tox_connection.cpp index aaa9b0ff29..6a3d9309df 100644 --- a/protocols/Tox/src/tox_connection.cpp +++ b/protocols/Tox/src/tox_connection.cpp @@ -5,56 +5,48 @@ bool CToxProto::IsOnline() return m_tox && m_iStatus >= ID_STATUS_ONLINE; } -void CToxProto::TryConnect() +///////////////////////////////////////////////////////////////////////////////////////// + +void CToxProto::OnLoggedIn() { - TOX_CONNECTION connectionStatus = tox_self_get_connection_status(m_tox); - if (connectionStatus != TOX_CONNECTION_NONE) { - debugLogA(__FUNCTION__": successfuly connected to DHT"); + debugLogA(__FUNCTION__": successfuly connected to DHT"); - m_iStatus = m_iDesiredStatus; - ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)ID_STATUS_CONNECTING, m_iStatus); - tox_self_set_status(m_tox, MirandaToToxStatus(m_iStatus)); + m_iStatus = m_iDesiredStatus; + ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)ID_STATUS_CONNECTING, m_iStatus); + tox_self_set_status(m_tox, MirandaToToxStatus(m_iStatus)); - debugLogA(__FUNCTION__": changing status from %i to %i", ID_STATUS_CONNECTING, m_iDesiredStatus); + debugLogA(__FUNCTION__": changing status from %i to %i", ID_STATUS_CONNECTING, m_iDesiredStatus); - UpdateStatusMenu(NULL, NULL); + UpdateStatusMenu(NULL, NULL); - LoadFriendList(m_tox); - return; - } + m_impl.timerPoll.Start(TOX_DEFAULT_INTERVAL); - int maxConnectRetries = getByte("MaxConnectRetries", TOX_MAX_CONNECT_RETRIES); - if (m_iStatus++ > maxConnectRetries) { - SetStatus(ID_STATUS_OFFLINE); - ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, nullptr, LOGINERR_NONETWORK); - debugLogA(__FUNCTION__": failed to connect to DHT"); - return; - } + LoadFriendList(m_tox); } -void CToxProto::CheckConnection() +void CToxProto::OnLoggedFail() { - int maxReconnectRetries = getByte("MaxReconnectRetries", TOX_MAX_RECONNECT_RETRIES); + int maxConnectRetries = getByte("MaxConnectRetries", TOX_MAX_CONNECT_RETRIES); - TOX_CONNECTION connectionStatus = tox_self_get_connection_status(m_tox); - if (connectionStatus != TOX_CONNECTION_NONE) { - if (m_retriesCount < maxReconnectRetries) { - debugLogA(__FUNCTION__": restored connection with DHT"); - m_retriesCount = maxReconnectRetries; + if (m_iStatus > ID_STATUS_OFFLINE) { + if (m_retriesCount == maxConnectRetries) { + m_retriesCount--; + debugLogA(__FUNCTION__": lost connection with DHT"); + return; } - return; - } - if (m_retriesCount == maxReconnectRetries) { - m_retriesCount--; - debugLogA(__FUNCTION__": lost connection with DHT"); - return; + if (!(--m_retriesCount)) { + debugLogA(__FUNCTION__": disconnected from DHT"); + SetStatus(ID_STATUS_OFFLINE); + return; + } } - - if (!(--m_retriesCount)) { - debugLogA(__FUNCTION__": disconnected from DHT"); - SetStatus(ID_STATUS_OFFLINE); - return; + else { + if (m_iStatus++ > maxConnectRetries) { + SetStatus(ID_STATUS_OFFLINE); + ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, nullptr, LOGINERR_NONETWORK); + debugLogA(__FUNCTION__": failed to connect to DHT"); + } } } @@ -63,20 +55,17 @@ void CToxProto::OnToxCheck() if (m_tox == nullptr) return; - // int retriesCount = proto->getByte("MaxReconnectRetries", TOX_MAX_RECONNECT_RETRIES); - if (m_iStatus < ID_STATUS_ONLINE) - TryConnect(); - else - CheckConnection(); + int iStatus = tox_self_get_connection_status(m_tox); + if (iStatus == TOX_CONNECTION_NONE) + OnLoggedFail(); + else if (iStatus != m_prevToxStatus) + OnLoggedIn(); + + m_prevToxStatus = iStatus; } void CToxProto::OnToxPoll() { if (m_tox) tox_iterate(m_tox, this); - - /*uint32_t interval = tox_iteration_interval(m_tox); - interval = interval - ? interval - : TOX_DEFAULT_INTERVAL;*/ } |