mirror of
https://github.com/MaaAssistantArknights/MaaAssistantArknights.git
synced 2026-07-17 01:59:33 +08:00
fix: add timeout for IOHandler read
This commit is contained in:
@@ -36,29 +36,16 @@ bool asst::MinitouchController::call_and_hup_minitouch()
|
||||
return false;
|
||||
}
|
||||
|
||||
auto check_timeout = [&](const auto& start_time) -> bool {
|
||||
using namespace std::chrono_literals;
|
||||
return std::chrono::steady_clock::now() - start_time < 3s;
|
||||
};
|
||||
if (need_exit()) {
|
||||
release_minitouch(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
const auto start_time = std::chrono::steady_clock::now();
|
||||
while (true) {
|
||||
if (need_exit()) {
|
||||
release_minitouch(true);
|
||||
return false;
|
||||
}
|
||||
pipe_str = m_minitouch_handler->read(3);
|
||||
|
||||
if (!check_timeout(start_time)) {
|
||||
Log.info("unable to find $ from pipe_str:", Logger::separator::newline, pipe_str);
|
||||
release_minitouch(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (pipe_str.find('$') != std::string::npos) {
|
||||
break;
|
||||
}
|
||||
|
||||
pipe_str += m_minitouch_handler->read();
|
||||
if (pipe_str.find('$') == std::string::npos) {
|
||||
release_minitouch(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
Log.info("pipe str", Logger::separator::newline, pipe_str);
|
||||
|
||||
Reference in New Issue
Block a user