1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

Faster file transfers (up to 160ms/s)

By reducing the maximum interval between two tox_iterate calls during file transfers to 10ms. This results in reasonnable amounts of extra CPU% used. If the only file transfers are avatars, CoreFile allows sleeping for up to 50ms. If there are currently no FT, up to 1000ms.

We now take the minimum sleeping interval asked by toxcore, toxav, and CoreFile
This commit is contained in:
tux3 2015-05-11 20:41:19 +02:00
parent ef688f6097
commit 7cb98b90c7
No known key found for this signature in database
GPG Key ID: 7E086DD661263264
3 changed files with 26 additions and 1 deletions

View File

@ -363,7 +363,9 @@ void Core::process()
tolerance = 3*CORE_DISCONNECT_TOLERANCE; 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() bool Core::checkConnection()

View File

@ -13,6 +13,25 @@ QMutex CoreFile::fileSendMutex;
QHash<uint64_t, ToxFile> CoreFile::fileMap; QHash<uint64_t, ToxFile> CoreFile::fileMap;
using namespace std; 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) void CoreFile::sendAvatarFile(Core* core, uint32_t friendId, const QByteArray& data)
{ {
QMutexLocker mlocker(&fileSendMutex); QMutexLocker mlocker(&fileSendMutex);

View File

@ -24,6 +24,7 @@ class CoreFile
private: private:
CoreFile()=delete; CoreFile()=delete;
// Internal file sending APIs, used by Core. Public API in core.h
private: private:
static void sendFile(Core *core, uint32_t friendId, QString Filename, QString FilePath, long long filesize); 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); 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 ToxFile *findFile(uint32_t friendId, uint32_t fileId);
static void addFile(uint32_t friendId, uint32_t fileId, const ToxFile& file); static void addFile(uint32_t friendId, uint32_t fileId, const ToxFile& file);
static void removeFile(uint32_t friendId, uint32_t fileId); 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: private:
static void onFileReceiveCallback(Tox*, uint32_t friendnumber, uint32_t fileId, uint32_t kind, static void onFileReceiveCallback(Tox*, uint32_t friendnumber, uint32_t fileId, uint32_t kind,