From 0bd7314a45df9f2b01aa2a1728fe46fe18c3cf67 Mon Sep 17 00:00:00 2001 From: Alexander Lantsev Date: Tue, 17 Feb 2015 21:16:52 +0000 Subject: Tox: fix to simultaneous file transfer to different contacts git-svn-id: http://svn.miranda-ng.org/main/trunk@12171 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/Tox/src/tox_transfer.cpp | 6 +++--- protocols/Tox/src/tox_transfer.h | 38 +++++++++++++++++++++----------------- 2 files changed, 24 insertions(+), 20 deletions(-) diff --git a/protocols/Tox/src/tox_transfer.cpp b/protocols/Tox/src/tox_transfer.cpp index e85babb1de..580e3aae75 100644 --- a/protocols/Tox/src/tox_transfer.cpp +++ b/protocols/Tox/src/tox_transfer.cpp @@ -126,7 +126,7 @@ void CToxProto::OnFileData(Tox *tox, int32_t friendNumber, uint8_t fileNumber, c return; } - FileTransferParam *transfer = proto->transfers->Get(fileNumber); + FileTransferParam *transfer = proto->transfers->Get(friendNumber, fileNumber); if (transfer == NULL) { proto->debugLogA("CToxProto::OnFileData: cannot find transfer by number (%d)", fileNumber); @@ -181,7 +181,7 @@ HANDLE __cdecl CToxProto::SendFile(MCONTACT hContact, const PROTOCHAR*, PROTOCHA char *name = mir_utf8encodeW(fileName); int fileNumber = tox_new_file_sender(tox, friendNumber, fileSize, (uint8_t*)name, (uint16_t)mir_strlen(name)); - if (fileNumber < 0) + if (fileNumber == TOX_ERROR) { debugLogA("CToxProto::SendFilesAsync: cannot send file"); return NULL; @@ -282,7 +282,7 @@ void CToxProto::OnFileRequest(Tox *tox, int32_t friendNumber, uint8_t receive_se MCONTACT hContact = proto->GetContact(friendNumber); if (hContact) { - FileTransferParam *transfer = proto->transfers->Get(fileNumber); + FileTransferParam *transfer = proto->transfers->Get(friendNumber, fileNumber); if (transfer == NULL) { tox_file_send_control(tox, friendNumber, receive_send, fileNumber, TOX_FILECONTROL_KILL, NULL, 0); diff --git a/protocols/Tox/src/tox_transfer.h b/protocols/Tox/src/tox_transfer.h index 643dc418f9..534565c09f 100644 --- a/protocols/Tox/src/tox_transfer.h +++ b/protocols/Tox/src/tox_transfer.h @@ -18,15 +18,17 @@ struct FileTransferParam PROTOFILETRANSFERSTATUS pfts; FILE_TRANSFER_STATUS status; FILE *hFile; - int friendNumber; - int fileNumber; + int32_t friendNumber; + uint8_t fileNumber; + int64_t transferNumber; - FileTransferParam(int friendNumber, int fileNumber, const TCHAR *fileName, uint64_t fileSize) + FileTransferParam(int32_t friendNumber, uint8_t fileNumber, const TCHAR *fileName, uint64_t fileSize) { status = NONE; hFile = NULL; this->friendNumber = friendNumber; this->fileNumber = fileNumber; + transferNumber = (((int64_t)friendNumber) << 32) | ((int64_t)fileNumber); pfts.cbSize = sizeof(PROTOFILETRANSFERSTATUS); pfts.flags = PFTS_TCHAR; @@ -76,7 +78,7 @@ struct FileTransferParam class CTransferList { private: - std::map transfers; + std::map transfers; public: size_t Count() const @@ -86,47 +88,49 @@ public: void Add(FileTransferParam *transfer) { - if (transfers.find(transfer->fileNumber) == transfers.end()) + if (transfers.find(transfer->transferNumber) == transfers.end()) { - transfers[transfer->fileNumber] = transfer; + transfers[transfer->transferNumber] = transfer; } } - FileTransferParam* Get(uint8_t fileNumber) + FileTransferParam* Get(int32_t friendNumber, uint8_t fileNumber) { - if (transfers.find(fileNumber) != transfers.end()) + int64_t transferNumber = (((int64_t)friendNumber) << 32) | ((int64_t)fileNumber); + if (transfers.find(transferNumber) != transfers.end()) { - return transfers.at(fileNumber); + return transfers.at(transferNumber); } return NULL; } - FileTransferParam* GetAt(size_t index) + FileTransferParam* GetAt(int64_t index) { if (index < Count()) { - std::map::iterator it = transfers.begin(); + std::map::iterator it = transfers.begin(); std::advance(it, index); return it->second; } return NULL; } - void Remove(uint8_t fileNumber) + void Remove(int32_t friendNumber, uint8_t fileNumber) { - if (transfers.find(fileNumber) != transfers.end()) + int64_t transferNumber = (((int64_t)friendNumber) << 32) | ((int64_t)fileNumber); + if (transfers.find(transferNumber) != transfers.end()) { - FileTransferParam *transfer = transfers.at(fileNumber); - transfers.erase(fileNumber); + FileTransferParam *transfer = transfers.at(transferNumber); + transfers.erase(transferNumber); delete transfer; } } void Remove(FileTransferParam *transfer) { - if (transfers.find(transfer->fileNumber) != transfers.end()) + if (transfers.find(transfer->transferNumber) != transfers.end()) { - transfers.erase(transfer->fileNumber); + transfers.erase(transfer->transferNumber); delete transfer; } } -- cgit v1.2.3