From d4d7eeaef5e5c7f1cb1e7c2a22447437128785b6 Mon Sep 17 00:00:00 2001 From: uye <99072975+ABA2396@users.noreply.github.com> Date: Mon, 27 May 2024 18:23:36 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20call=5Fcommand=20timeout=E6=97=B6?= =?UTF-8?q?=E6=8F=90=E5=89=8D=E8=BF=94=E5=9B=9E=20std::nullopt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fix #9218 fix #9102 --- src/MaaCore/Controller/AdbController.cpp | 1 + src/MaaCore/Controller/Platform/Win32IO.cpp | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/MaaCore/Controller/AdbController.cpp b/src/MaaCore/Controller/AdbController.cpp index 180854c07c..a49eb521e7 100644 --- a/src/MaaCore/Controller/AdbController.cpp +++ b/src/MaaCore/Controller/AdbController.cpp @@ -137,6 +137,7 @@ std::optional asst::AdbController::call_command( m_platform_io->call_command(cmd, recv_by_socket, pipe_data, sock_data, timeout, start_time); if (!exit_res) { + Log.warn("Call `", cmd, "` failed"); return std::nullopt; } const int exit_ret = exit_res.value(); diff --git a/src/MaaCore/Controller/Platform/Win32IO.cpp b/src/MaaCore/Controller/Platform/Win32IO.cpp index bb11b40035..0a0638db33 100644 --- a/src/MaaCore/Controller/Platform/Win32IO.cpp +++ b/src/MaaCore/Controller/Platform/Win32IO.cpp @@ -152,11 +152,23 @@ std::optional asst::Win32IO::call_command(const std::string& cmd, bool recv handle_string.emplace_back("UnknownHandle"); } } - Log.warn("Wait handles:", handle_string, "timeout."); + Log.warn("Wait handles:", handle_string, " after", timeout, "ms."); if (process_running) { TerminateProcess(process_info.hProcess, 0); } - break; + // 处理超时后返回 std::nullopt + CloseHandle(pipe_parent_read); + CloseHandle(pipeov.hEvent); + CloseHandle(process_info.hProcess); + CloseHandle(process_info.hThread); + if (recv_by_socket) { + CloseHandle(sockov.hEvent); + if (client_socket != INVALID_SOCKET) { + closesocket(client_socket); + } + } + return std::nullopt; + // break; } continue; }