fix: add timeout for IOHandler read

This commit is contained in:
shxyke
2023-03-28 02:02:18 +00:00
parent 24493835ce
commit 002a05fef4
8 changed files with 48 additions and 56 deletions

View File

@@ -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);