From e7cd546afb94b3c80d5ec08adc7aa0235fb061e5 Mon Sep 17 00:00:00 2001 From: gb <741021719@qq.com> Date: Thu, 30 Nov 2023 09:16:13 +0800 Subject: [PATCH] add time-out control for APP image fetching in scan_done --- sane/scanner.cpp | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/sane/scanner.cpp b/sane/scanner.cpp index 6860cd9..fcc0c02 100644 --- a/sane/scanner.cpp +++ b/sane/scanner.cpp @@ -807,8 +807,25 @@ void scanner::scan_done(void) { std::string msg(scan_msg_); - while (images_.count()) - std::this_thread::sleep_for(std::chrono::milliseconds(5)); + // avoid APP do not fetch image ... - 2023-11-30 + if (err_ != SCANNER_ERR_USER_CANCELED) + { + int cnt = images_.count(), + wait_total = 1000, + wait_unit = 5, + wait = 0; + + while (cnt) + { + std::this_thread::sleep_for(std::chrono::milliseconds(wait_unit)); + wait++; + if (wait >= wait_total / wait_unit) + break; + else if (cnt != images_.count()) + wait = 0; + cnt = images_.count(); + } + } if (indicator_) indicator_->notify_scan_over(&msg[0], err_ != SCANNER_ERR_OK);