apr:handle some offline situ.

This commit is contained in:
2025-10-20 16:40:52 +08:00
parent e2f04dde62
commit 0c4c5ff4de
9 changed files with 40 additions and 58 deletions

View File

@@ -176,6 +176,10 @@ void ClientCore::UseFrame(QSharedPointer<FrameBuffer> frame)
emit sigFileInfo(frame);
break;
}
case FBT_SER_MSG_OFFLINE: {
emit sigOffline(frame);
break;
}
default:
qCritical() << QString("unknown frame type: %1").arg(frame->type);
break;
@@ -276,33 +280,11 @@ void HeatBeat::run()
continue;
}
ClientCore::syncInvoke(core_, frame);
}
}
TransBeat::TransBeat(ClientCore* core, QObject* parent) : QThread(parent), core_(core)
{
}
TransBeat::~TransBeat()
{
Stop();
}
void TransBeat::run()
{
isRun_ = true;
InfoMsg info;
while (isRun_) {
QThread::sleep(1);
if (!core_->IsConnect()) {
auto rid = core_->GetRemoteID();
if (rid.isEmpty()) {
continue;
}
auto frame = core_->GetBuffer(info, FBT_SER_MSG_JUDGE_OTHER_ALIVE, core_->GetRemoteID());
ClientCore::syncInvoke(core_, frame);
auto frame2 = core_->GetBuffer(info, FBT_SER_MSG_JUDGE_OTHER_ALIVE, rid);
ClientCore::syncInvoke(core_, frame2);
}
}
void TransBeat::Stop()
{
isRun_ = false;
}
}

View File

@@ -76,6 +76,7 @@ signals:
void sigFileBuffer(QSharedPointer<FrameBuffer> frame);
void sigTransFailed(QSharedPointer<FrameBuffer> frame);
void sigFileInfo(QSharedPointer<FrameBuffer> frame);
void sigOffline(QSharedPointer<FrameBuffer> frame);
signals:
void conSuccess();
@@ -143,24 +144,4 @@ private:
ClientCore* core_{};
};
// judge send client is alive or not when downloading
class TransBeat : public QThread
{
Q_OBJECT
public:
TransBeat(ClientCore* core, QObject* parent = nullptr);
~TransBeat() override;
public:
void Stop();
protected:
void run() override;
private:
bool isRun_{false};
ClientCore* core_{};
};
#endif // CLIENTCORE_H

View File

@@ -17,13 +17,11 @@ FileTrans::FileTrans(ClientCore* clientCore) : clientCore_(clientCore)
*/
void FileTrans::ReqSendFile(const TransTask& task)
{
sendTask_->state = TaskState::STATE_RUNNING;
// TODO: check if running...
if (sendTask_->file.isOpen()) {
qWarning() << QString(tr("file [%1] is running.")).arg(sendTask_->file.fileName());
while (sendTask_->file.isOpen()) {
QThread::msleep(1);
}
qWarning() << QString(tr("file [%1] is exit running.")).arg(sendTask_->file.fileName());
qWarning() << QString(tr("file [%1] is already opened, will auto close.")).arg(sendTask_->file.fileName());
sendTask_->file.close();
}
// start
InfoMsg info;
@@ -146,6 +144,7 @@ void FileTrans::RegisterSignal()
connect(clientCore_, &ClientCore::sigFileBuffer, this, [this](QSharedPointer<FrameBuffer> frame) { fbtFileBuffer(frame); });
connect(clientCore_, &ClientCore::sigFileInfo, this, [this](QSharedPointer<FrameBuffer> frame) { fbtFileInfo(frame); });
connect(clientCore_, &ClientCore::sigTransFailed, this, [this](QSharedPointer<FrameBuffer> frame) { fbtTransFailed(frame); });
connect(clientCore_, &ClientCore::sigOffline, this, [this](QSharedPointer<FrameBuffer> frame) { fbtInterrupt(frame); });
}
// The other party requests to send, prepare to receive.
@@ -317,6 +316,18 @@ void FileTrans::fbtTransFailed(QSharedPointer<FrameBuffer> frame)
downTask_->state = TaskState::STATE_FAILED;
}
void FileTrans::fbtInterrupt(QSharedPointer<FrameBuffer> frame)
{
if (downTask_->state == TaskState::STATE_RUNNING) {
qWarning() << QString(tr("trans file:%1 interrupt.")).arg(downTask_->file.fileName());
downTask_->state = TaskState::STATE_NONE;
}
if (sendTask_->state == TaskState::STATE_RUNNING) {
qWarning() << QString(tr("trans file:%1 interrupt.")).arg(sendTask_->file.fileName());
sendTask_->state = TaskState::STATE_NONE;
}
}
void FileTrans::SendFile(const QSharedPointer<DoTransTask>& task)
{
auto* sendThread = new SendThread(clientCore_);

View File

@@ -78,6 +78,7 @@ private:
void fbtCanotSend(QSharedPointer<FrameBuffer> frame);
void fbtCanSend(QSharedPointer<FrameBuffer> frame);
void fbtTransFailed(QSharedPointer<FrameBuffer> frame);
void fbtInterrupt(QSharedPointer<FrameBuffer> frame);
private:
void RegisterSignal();