diff options
author | Alexander Lantsev <aunsane@gmail.com> | 2015-09-10 11:58:58 +0000 |
---|---|---|
committer | Alexander Lantsev <aunsane@gmail.com> | 2015-09-10 11:58:58 +0000 |
commit | 510f938a5c6f0ee95ac0b36e56aced065228298e (patch) | |
tree | 19f907a09498b6f76a4b7aae6ee90a16bf693aa2 /protocols/Tox/src/tox_network.cpp | |
parent | 86c868a76a5ba3d638b3b7302cd5401df06591d8 (diff) |
Tox: tox pointers should store in PollingThread to avoid cross thread using
git-svn-id: http://svn.miranda-ng.org/main/trunk@15316 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/Tox/src/tox_network.cpp')
-rw-r--r-- | protocols/Tox/src/tox_network.cpp | 47 |
1 files changed, 25 insertions, 22 deletions
diff --git a/protocols/Tox/src/tox_network.cpp b/protocols/Tox/src/tox_network.cpp index 8db001a5a5..03134d1034 100644 --- a/protocols/Tox/src/tox_network.cpp +++ b/protocols/Tox/src/tox_network.cpp @@ -2,7 +2,7 @@ bool CToxProto::IsOnline()
{
- return isConnected && m_iStatus >= ID_STATUS_ONLINE;
+ return toxThread && toxThread->isConnected && m_iStatus >= ID_STATUS_ONLINE;
}
void CToxProto::BootstrapNode(const char *address, int port, const char *hexKey)
@@ -11,10 +11,10 @@ void CToxProto::BootstrapNode(const char *address, int port, const char *hexKey) return;
ToxBinAddress binKey(hexKey, TOX_PUBLIC_KEY_SIZE * 2);
TOX_ERR_BOOTSTRAP error;
- if (!tox_bootstrap(tox, address, port, binKey, &error))
+ if (!tox_bootstrap(toxThread->tox, address, port, binKey, &error))
debugLogA(__FUNCTION__ ": failed to bootstrap node %s:%d \"%s\" (%d)", address, port, hexKey, error);
- if (!tox_add_tcp_relay(tox, address, port, binKey, &error))
- debugLogA(__FUNCTION__ ": failed to add tcp relay%s:%d \"%s\" (%d)", address, port, hexKey, error);
+ if (!tox_add_tcp_relay(toxThread->tox, address, port, binKey, &error))
+ debugLogA(__FUNCTION__ ": failed to add tcp relay %s:%d \"%s\" (%d)", address, port, hexKey, error);
}
void CToxProto::BootstrapNodesFromDb(bool isIPv6)
@@ -86,16 +86,16 @@ void CToxProto::BootstrapNodes() void CToxProto::TryConnect()
{
- if (tox_self_get_connection_status(tox) != TOX_CONNECTION_NONE)
+ if (tox_self_get_connection_status(toxThread->tox) != TOX_CONNECTION_NONE)
{
- isConnected = true;
+ toxThread->isConnected = true;
debugLogA(__FUNCTION__": successfuly connected to DHT");
ForkThread(&CToxProto::LoadFriendList, NULL);
m_iStatus = m_iDesiredStatus;
ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)ID_STATUS_CONNECTING, m_iStatus);
- tox_self_set_status(tox, MirandaToToxStatus(m_iStatus));
+ tox_self_set_status(toxThread->tox, MirandaToToxStatus(m_iStatus));
debugLogA(__FUNCTION__": changing status from %i to %i", ID_STATUS_CONNECTING, m_iDesiredStatus);
}
else if (m_iStatus++ > TOX_MAX_CONNECT_RETRIES)
@@ -108,11 +108,11 @@ void CToxProto::TryConnect() void CToxProto::CheckConnection(int &retriesCount)
{
- if (!isConnected)
+ if (!toxThread->isConnected)
{
TryConnect();
}
- else if (tox_self_get_connection_status(tox) != TOX_CONNECTION_NONE)
+ else if (tox_self_get_connection_status(toxThread->tox) != TOX_CONNECTION_NONE)
{
if (retriesCount < TOX_MAX_DISCONNECT_RETRIES)
{
@@ -134,30 +134,33 @@ void CToxProto::CheckConnection(int &retriesCount) }
else if (!(--retriesCount))
{
- isConnected = false;
+ toxThread->isConnected = false;
debugLogA(__FUNCTION__": disconnected from DHT");
SetStatus(ID_STATUS_OFFLINE);
}
}
}
-void CToxProto::DoTox()
+void DoTox(ToxThreadData *toxThread)
{
{
- mir_cslock lock(toxLock);
- tox_iterate(tox);
- if (toxAv)
- toxav_do(toxAv);
+ mir_cslock lock(toxThread->toxLock);
+ tox_iterate(toxThread->tox);
+ if (toxThread->toxAv)
+ toxav_do(toxThread->toxAv);
}
- uint32_t interval = tox_iteration_interval(tox);
+ uint32_t interval = tox_iteration_interval(toxThread->tox);
Sleep(interval);
}
void CToxProto::PollingThread(void*)
{
+ ToxThreadData toxThread;
+ this->toxThread = &toxThread;
+
debugLogA(__FUNCTION__": entering");
- if (!InitToxCore())
+ if (!InitToxCore(&toxThread))
{
SetStatus(ID_STATUS_OFFLINE);
ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, (HANDLE)NULL, LOGINERR_WRONGPASSWORD);
@@ -166,17 +169,17 @@ void CToxProto::PollingThread(void*) }
int retriesCount = TOX_MAX_DISCONNECT_RETRIES;
- isConnected = false;
+ toxThread.isConnected = false;
BootstrapNodes();
- while (!isTerminated)
+ while (!toxThread.isTerminated)
{
CheckConnection(retriesCount);
- DoTox();
+ DoTox(&toxThread);
}
- UninitToxCore();
- isConnected = false;
+ UninitToxCore(&toxThread);
+ toxThread.isConnected = false;
debugLogA(__FUNCTION__": leaving");
}
\ No newline at end of file |