summaryrefslogtreecommitdiff
path: root/protocols
diff options
context:
space:
mode:
authoraunsane <aunsane@gmail.com>2018-08-09 22:21:45 +0300
committeraunsane <aunsane@gmail.com>2018-08-09 22:21:45 +0300
commitc0c34a265b56d3e1ee4cf4d772d503608aafbcf9 (patch)
tree529dcd87e8dbf725b805f891f8a23c84550a5945 /protocols
parent7258aff5987814c6a106b1e8c4bab975e34b7012 (diff)
Tox: attempt to fix #1541
Diffstat (limited to 'protocols')
-rw-r--r--protocols/Tox/src/tox_connection.cpp12
-rw-r--r--protocols/Tox/src/tox_proto.cpp21
-rw-r--r--protocols/Tox/src/tox_proto.h1
-rw-r--r--protocols/Tox/src/tox_thread.h13
4 files changed, 30 insertions, 17 deletions
diff --git a/protocols/Tox/src/tox_connection.cpp b/protocols/Tox/src/tox_connection.cpp
index 564490e2e1..41fca21d6e 100644
--- a/protocols/Tox/src/tox_connection.cpp
+++ b/protocols/Tox/src/tox_connection.cpp
@@ -61,13 +61,13 @@ void CToxProto::CheckingThread(void *arg)
debugLogA(__FUNCTION__": entering");
- Tox *tox = (Tox*)arg;
+ CToxThread *thread = (CToxThread*)arg;
int retriesCount = getByte("MaxReconnectRetries", TOX_MAX_RECONNECT_RETRIES);
- while (!isTerminated) {
+ while (!thread->IsTerminated()) {
if (m_iStatus < ID_STATUS_ONLINE)
- TryConnect(tox);
+ TryConnect(thread->Tox());
else
- CheckConnection(tox, retriesCount);
+ CheckConnection(thread->Tox(), retriesCount);
WaitForSingleObject(hTerminateEvent, TOX_CHECKING_INTERVAL);
}
@@ -106,9 +106,9 @@ void CToxProto::PollingThread(void*)
m_toxThread = &toxThread;
InitToxCore(toxThread.Tox());
BootstrapNodes(toxThread.Tox());
- hCheckingThread = ForkThreadEx(&CToxProto::CheckingThread, toxThread.Tox(), nullptr);
+ hCheckingThread = ForkThreadEx(&CToxProto::CheckingThread, &toxThread, nullptr);
- while (!isTerminated) {
+ while (!toxThread.IsTerminated()) {
tox_iterate(toxThread.Tox(), this);
uint32_t interval = tox_iteration_interval(toxThread.Tox());
interval = interval
diff --git a/protocols/Tox/src/tox_proto.cpp b/protocols/Tox/src/tox_proto.cpp
index 0ae5b521ec..8cdcd6c56f 100644
--- a/protocols/Tox/src/tox_proto.cpp
+++ b/protocols/Tox/src/tox_proto.cpp
@@ -2,8 +2,9 @@
CToxProto::CToxProto(const char* protoName, const wchar_t* userName)
: PROTO<CToxProto>(protoName, userName),
- m_toxThread(nullptr), isTerminated(false),
- hCheckingThread(nullptr), hPollingThread(nullptr),
+ m_toxThread(nullptr),
+ hCheckingThread(nullptr),
+ hPollingThread(nullptr),
hMessageProcess(1)
{
InitNetlib();
@@ -163,16 +164,19 @@ int CToxProto::SetStatus(int iNewStatus)
// logout
if (iNewStatus == ID_STATUS_OFFLINE) {
- isTerminated = true;
- SetEvent(hTerminateEvent);
+ if (m_toxThread != nullptr) {
+ m_toxThread->Terminate();
+ SetEvent(hTerminateEvent);
+ }
- if (!Miranda_IsTerminated())
+ if (!Miranda_IsTerminated()) {
setAllContactStatuses(ID_STATUS_OFFLINE);
- m_iStatus = m_iDesiredStatus = ID_STATUS_OFFLINE;
- ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)old_status, m_iStatus);
+ m_iStatus = m_iDesiredStatus = ID_STATUS_OFFLINE;
+ ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)old_status, m_iStatus);
- UpdateStatusMenu(NULL, NULL);
+ UpdateStatusMenu(NULL, NULL);
+ }
return 0;
}
@@ -182,7 +186,6 @@ int CToxProto::SetStatus(int iNewStatus)
// login
if (old_status == ID_STATUS_OFFLINE && !IsOnline()) {
- isTerminated = false;
m_iStatus = ID_STATUS_CONNECTING;
ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)old_status, m_iStatus);
diff --git a/protocols/Tox/src/tox_proto.h b/protocols/Tox/src/tox_proto.h
index 37028045e9..9ea063c4ab 100644
--- a/protocols/Tox/src/tox_proto.h
+++ b/protocols/Tox/src/tox_proto.h
@@ -68,7 +68,6 @@ private:
CTransferList transfers;
ULONG hMessageProcess;
- bool isTerminated;
HANDLE hConnectingThread;
HANDLE hCheckingThread;
HANDLE hPollingThread;
diff --git a/protocols/Tox/src/tox_thread.h b/protocols/Tox/src/tox_thread.h
index d47138822e..a56de4bab2 100644
--- a/protocols/Tox/src/tox_thread.h
+++ b/protocols/Tox/src/tox_thread.h
@@ -5,10 +5,11 @@ class CToxThread
{
private:
Tox *tox;
+ bool isTerminated;
public:
CToxThread(Tox_Options *options, TOX_ERR_NEW *error = nullptr)
- : tox(nullptr)
+ : tox(nullptr), isTerminated(false)
{
tox = tox_new(options, error);
}
@@ -27,6 +28,16 @@ public:
{
return tox;
}
+
+ bool IsTerminated()
+ {
+ return isTerminated;
+ }
+
+ void Terminate()
+ {
+ isTerminated = true;
+ }
};
#endif //_TOX_THREAD_H_ \ No newline at end of file