From b3a63d4e727b8552f8cf2b321cc68d2631ef3179 Mon Sep 17 00:00:00 2001 From: Alexander Lantsev Date: Sun, 10 Aug 2014 14:20:09 +0000 Subject: Tox: refactoring git-svn-id: http://svn.miranda-ng.org/main/trunk@10144 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/Tox/src/tox_account.cpp | 63 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 protocols/Tox/src/tox_account.cpp (limited to 'protocols/Tox/src/tox_account.cpp') diff --git a/protocols/Tox/src/tox_account.cpp b/protocols/Tox/src/tox_account.cpp new file mode 100644 index 0000000000..9c59965bc7 --- /dev/null +++ b/protocols/Tox/src/tox_account.cpp @@ -0,0 +1,63 @@ +#include "common.h" +#include "tox_bootstrap.h" + +void CToxProto::DoBootstrap() +{ + static int j = 0; + int i = 0; + while (i < 2) + { + struct bootstrap_node *d = &bootstrap_nodes[j % SIZEOF(bootstrap_nodes)]; + tox_bootstrap_from_address(tox, d->address, TOX_ENABLE_IPV6_DEFAULT, d->port, d->key); + i++; j++; + } +} + +void CToxProto::DoTox() +{ + uint32_t interval = 1000; + { + //mir_cslock lock(tox_lock); + + tox_do(tox); + interval = tox_do_interval(tox); + } + Sleep(interval); +} + +void CToxProto::PollingThread(void*) +{ + debugLogA("CToxProto::PollingThread: entering"); + + while (!isTerminated) + { + DoTox(); + } + + debugLogA("CToxProto::PollingThread: leaving"); +} + +void CToxProto::ConnectionThread(void*) +{ + debugLogA("CToxProto::ConnectionThread: entering"); + + while (!isTerminated && !isConnected) + { + DoBootstrap(); + + if (tox_isconnected(tox)) + { + isConnected = true; + break; + } + + DoTox(); + } + + if (!isTerminated && isConnected) + { + poolingThread = ForkThreadEx(&CToxProto::PollingThread, 0, NULL); + } + + debugLogA("CToxProto::ConnectionThread: leaving"); +} \ No newline at end of file -- cgit v1.2.3