diff --git a/src/core/core.cpp b/src/core/core.cpp index 39eff2ce8..bca66d2dc 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp @@ -363,7 +363,9 @@ void Core::process() tolerance = 3*CORE_DISCONNECT_TOLERANCE; } - toxTimer->start(qMin(tox_iteration_interval(tox), toxav_do_interval(toxav))); + unsigned sleeptime = qMin(tox_iteration_interval(tox), toxav_do_interval(toxav)); + sleeptime = qMin(sleeptime, CoreFile::corefileIterationInterval()); + toxTimer->start(sleeptime); } bool Core::checkConnection() diff --git a/src/core/corefile.cpp b/src/core/corefile.cpp index 744318f2f..41f805a3e 100644 --- a/src/core/corefile.cpp +++ b/src/core/corefile.cpp @@ -13,6 +13,25 @@ QMutex CoreFile::fileSendMutex; QHash CoreFile::fileMap; using namespace std; +unsigned CoreFile::corefileIterationInterval() +{ + /// Sleep at most 1000ms if we have no FT, 10 for user FTs, 50 for the rest (avatars, ...) + constexpr unsigned fastFileInterval=10, slowFileInterval=50, idleInterval=1000; + unsigned interval = idleInterval; + + for (ToxFile& file : fileMap) + { + if (file.status == ToxFile::TRANSMITTING) + { + if (file.fileKind == TOX_FILE_KIND_DATA) + return fastFileInterval; + else + interval = slowFileInterval; + } + } + return interval; +} + void CoreFile::sendAvatarFile(Core* core, uint32_t friendId, const QByteArray& data) { QMutexLocker mlocker(&fileSendMutex); diff --git a/src/core/corefile.h b/src/core/corefile.h index 9588bb545..40539e8d3 100644 --- a/src/core/corefile.h +++ b/src/core/corefile.h @@ -24,6 +24,7 @@ class CoreFile private: CoreFile()=delete; + // Internal file sending APIs, used by Core. Public API in core.h private: static void sendFile(Core *core, uint32_t friendId, QString Filename, QString FilePath, long long filesize); static void sendAvatarFile(Core* core, uint32_t friendId, const QByteArray& data); @@ -36,6 +37,9 @@ private: static ToxFile *findFile(uint32_t friendId, uint32_t fileId); static void addFile(uint32_t friendId, uint32_t fileId, const ToxFile& file); static void removeFile(uint32_t friendId, uint32_t fileId); + /// Returns the maximum amount of time in ms that Core should wait between two + /// tox_iterate calls to get good file transfer performances + static unsigned corefileIterationInterval(); private: static void onFileReceiveCallback(Tox*, uint32_t friendnumber, uint32_t fileId, uint32_t kind,