From cb5e5ff8b9b97471a1680084347027ebc2b9baad Mon Sep 17 00:00:00 2001 From: taynpg Date: Wed, 25 Jun 2025 16:07:18 +0800 Subject: [PATCH] fix: xp support code ver trans bug. --- ClientCore/ClientCore.h | 3 --- ClientCore/FileTrans.cpp | 44 +++++++--------------------------------- ClientCore/FileTrans.h | 1 - Gui/main.cpp | 1 + Protocol/Protocol.h | 1 - 5 files changed, 8 insertions(+), 42 deletions(-) diff --git a/ClientCore/ClientCore.h b/ClientCore/ClientCore.h index 369cb5b..5040a35 100644 --- a/ClientCore/ClientCore.h +++ b/ClientCore/ClientCore.h @@ -8,15 +8,12 @@ #include #include #include -#include -#include #include #include #include #include #include #include -#include #include class ClientCore : public QObject diff --git a/ClientCore/FileTrans.cpp b/ClientCore/FileTrans.cpp index 1bb1ba4..a0dc21c 100644 --- a/ClientCore/FileTrans.cpp +++ b/ClientCore/FileTrans.cpp @@ -236,8 +236,6 @@ void FileTrans::fbtTransDone(QSharedPointer frame) downTask_->state = TaskState::STATE_FINISH; info.msg = QString(tr("recv file:%1 success.")).arg(downTask_->file.fileName()); qInfo() << info.msg; - auto f = clientCore_->GetBuffer(info, FBT_CLI_CAN_DOWN, frame->fid); - ClientCore::syncInvoke(clientCore_, f); return; } qCritical() << QString(tr("recv file:%1 done sigal, but file not opened.")).arg(info.msg); @@ -251,7 +249,7 @@ void FileTrans::fbtCanDown(QSharedPointer frame) downTask_->permission = info.permissions; downTask_->totalSize = info.size; downTask_->tranSize = 0; - qDebug() << QString(tr("start trans file:%1.")).arg(info.fromPath); + qDebug() << QString(tr("Can Down trans file:%1.")).arg(info.fromPath); } void FileTrans::fbtCanotDown(QSharedPointer frame) @@ -299,7 +297,7 @@ void FileTrans::fbtCanotSend(QSharedPointer frame) void FileTrans::fbtCanSend(QSharedPointer frame) { InfoMsg info = infoUnpack(frame->data); - qInfo() << QString(tr("start trans file:%1 to %2")).arg(info.fromPath, frame->fid); + qInfo() << QString(tr("Can Send start trans file:%1 to %2")).arg(info.fromPath, frame->fid); SendFile(sendTask_); } @@ -330,12 +328,12 @@ void SendThread::run() { // task's file shoule be already opened. isSuccess_ = true; + bool invokeSuccess = false; while (!task_->file.atEnd()) { auto frame = QSharedPointer::create(); frame->tid = task_->task.remoteId; frame->type = FBT_CLI_FILE_BUFFER; - frame->call = [this](QSharedPointer frame) { sendCall(frame); }; frame->data.resize(CHUNK_BUF_SIZE); auto br = task_->file.read(frame->data.data(), CHUNK_BUF_SIZE); @@ -345,32 +343,14 @@ void SendThread::run() break; } frame->data.resize(br); - - while (curSendCount_ >= MAX_SEND_TASK) { - QThread::msleep(1); - // shoule add abort action mark. - } - - // QMetaObject::invokeMethod(cliCore_, [this, frame] { - // frame->sendRet = cliCore_->Send(frame); - // if (frame->call) { - // frame->call(frame); - // } - // }); - - ++curSendCount_; - - if (!isSuccess_) { + invokeSuccess = QMetaObject::invokeMethod(cliCore_, "SendFrame", Qt::BlockingQueuedConnection, + Q_RETURN_ARG(bool, isSuccess_), Q_ARG(QSharedPointer, frame)); + if (!invokeSuccess || !isSuccess_) { qCritical() << QString(tr("send to %1 file failed.")).arg(task_->task.remoteId); break; } + task_->tranSize += frame->data.size(); } - - while (curSendCount_ > 0) { - QThread::msleep(1); - // shoule add abort action mark. - } - InfoMsg info; auto f = cliCore_->GetBuffer(info, FBT_CLI_TRANS_DONE, task_->task.remoteId); ClientCore::syncInvoke(cliCore_, f); @@ -382,13 +362,3 @@ void SendThread::setTask(const QSharedPointer& task) { task_ = task; } - -void SendThread::sendCall(QSharedPointer frame) -{ - if (frame->sendRet) { - --curSendCount_; - task_->tranSize += frame->data.size(); - } else { - isSuccess_ = false; - } -} diff --git a/ClientCore/FileTrans.h b/ClientCore/FileTrans.h index 8358baa..552eff3 100644 --- a/ClientCore/FileTrans.h +++ b/ClientCore/FileTrans.h @@ -46,7 +46,6 @@ public: public: void run() override; void setTask(const QSharedPointer& task); - void sendCall(QSharedPointer frame); private: bool isSuccess_{false}; diff --git a/Gui/main.cpp b/Gui/main.cpp index d9036d7..7e23939 100644 --- a/Gui/main.cpp +++ b/Gui/main.cpp @@ -36,6 +36,7 @@ int main(int argc, char* argv[]) qRegisterMetaType>("QSharedPointer"); qRegisterMetaType("InfoClientVec"); qRegisterMetaType("DirFileInfoVec"); + qRegisterMetaType("TransTask"); frelayGUI w; diff --git a/Protocol/Protocol.h b/Protocol/Protocol.h index dafc1a4..db3bca4 100644 --- a/Protocol/Protocol.h +++ b/Protocol/Protocol.h @@ -42,7 +42,6 @@ struct FrameBuffer { QString tid; FrameBufferType type = FBT_NONE; bool sendRet; - std::function)> call{}; }; class Protocol