trans: success to trans one file.

This commit is contained in:
2025-06-19 22:07:12 +08:00
parent 5890b66309
commit 182f8faad5
8 changed files with 41 additions and 21 deletions

View File

@@ -100,6 +100,7 @@ void ClientCore::UseFrame(QSharedPointer<FrameBuffer> frame)
break;
}
case FrameBufferType::FBT_SER_MSG_FORWARD_FAILED: {
qCritical() << QString(tr("************************** forward failed."));
break;
}
case FrameBufferType::FBT_CLI_REQ_SEND: {
@@ -111,31 +112,31 @@ void ClientCore::UseFrame(QSharedPointer<FrameBuffer> frame)
break;
}
case FrameBufferType::FBT_CLI_TRANS_DONE: {
sigTransDone(frame);
emit sigTransDone(frame);
break;
}
case FrameBufferType::FBT_CLI_CAN_SEND: {
sigCanSend(frame);
emit sigCanSend(frame);
break;
}
case FrameBufferType::FBT_CLI_CANOT_SEND: {
sigCanotSend(frame);
emit sigCanotSend(frame);
break;
}
case FBT_CLI_CANOT_DOWN: {
sigCanotDown(frame);
emit sigCanotDown(frame);
break;
}
case FBT_CLI_CAN_DOWN: {
sigCanDown(frame);
emit sigCanDown(frame);
break;
}
case FBT_CLI_FILE_BUFFER: {
sigFileBuffer(frame);
emit sigFileBuffer(frame);
break;
}
case FBT_CLI_TRANS_FAILED: {
sigTransFailed(frame);
emit sigTransFailed(frame);
break;
}
default:

View File

@@ -52,6 +52,7 @@ void FileTrans::ReqSendFile(const TransTask& task)
sendTask_->state = TaskState::STATE_RUNNING;
sendTask_->totalSize = info.size;
sendTask_->tranSize = 0;
sendTask_->task = task;
}
void FileTrans::ReqDownFile(const TransTask& task)
@@ -269,14 +270,15 @@ SendThread::SendThread(ClientCore* clientCore) : cliCore_(clientCore)
void SendThread::run()
{
// task's file shoule be already opened.
auto frame = QSharedPointer<FrameBuffer>::create();
frame->tid = task_->task.remoteId;
frame->type = FBT_CLI_FILE_BUFFER;
frame->call = [this](QSharedPointer<FrameBuffer> frame) { sendCall(frame); };
isSuccess_ = true;
while (!task_->file.atEnd()) {
auto frame = QSharedPointer<FrameBuffer>::create();
frame->tid = task_->task.remoteId;
frame->type = FBT_CLI_FILE_BUFFER;
frame->call = [this](QSharedPointer<FrameBuffer> frame) { sendCall(frame); };
frame->data.resize(CHUNK_BUF_SIZE);
auto br = task_->file.read(frame->data.data(), CHUNK_BUF_SIZE);
if (br == -1) {
qCritical() << QString(tr("read file failed: %1")).arg(task_->file.errorString());
@@ -303,6 +305,15 @@ void SendThread::run()
break;
}
}
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::asyncInvoke(cliCore_, [this, f]() { return cliCore_->Send(f); });
task_->file.close();
}