diff --git a/drivermanger.cpp b/drivermanger.cpp index 98b7ca7..58332f8 100644 --- a/drivermanger.cpp +++ b/drivermanger.cpp @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd. +// SPDX-FileCopyrightText: 2022 - 2026 UnionTech Software Technology Co., Ltd. // // SPDX-License-Identifier: LGPL-3.0-or-later @@ -117,6 +117,7 @@ void DriverManger::enrollStop(QString actionId, ErrMsgInfo &errMsgInfo) } } qDebug() << "start Erollthread stop"; + m_spErollthread->m_stopCapture = true; QMetaObject::invokeMethod(m_spErollthread.data(), "Stop", Qt::BlockingQueuedConnection); m_actionMap.remove(actionId); diff --git a/workmodule.cpp b/workmodule.cpp index c538578..60a28ef 100644 --- a/workmodule.cpp +++ b/workmodule.cpp @@ -111,11 +111,22 @@ void ErollThread::sendCapture(QImage &img) } unsigned long countSize = size; + int retryCount = 0; while (countSize > 0 && !m_stopCapture) { long sendSize = write(m_fileSocket, &buf[size - countSize], static_cast(countSize)); if (sendSize < 0) { - continue; + if (errno == EAGAIN || errno == EWOULDBLOCK) { + retryCount++; + if (retryCount > 100) { + break; + } + QThread::msleep(1); + continue; + } + qWarning() << "write error:" << strerror(errno); + break; } + retryCount = 0; countSize -= static_cast(sendSize); } free(buf); diff --git a/workmodule.h b/workmodule.h index 3dc5873..5d7ff35 100644 --- a/workmodule.h +++ b/workmodule.h @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd. +// SPDX-FileCopyrightText: 2022 - 2026 UnionTech Software Technology Co., Ltd. // // SPDX-License-Identifier: LGPL-3.0-or-later @@ -6,6 +6,7 @@ #define WORKMODULE_H #include +#include #include #include #include @@ -46,6 +47,9 @@ private Q_SLOTS: void captureError(int err, QImageCapture::Error, const QString &errorString); void processCapturedImage(int id, const QImage &preview); +public: + std::atomic m_stopCapture; + private: QScopedPointer m_camera; QScopedPointer m_imageCapture; @@ -53,7 +57,6 @@ private Q_SLOTS: QString m_actionId; int m_fileSocket; bool m_bFirst; - bool m_stopCapture; bool m_checkDone; };