From 60c5455c57996e5fb8d9602e31579f6ed24627e6 Mon Sep 17 00:00:00 2001 From: fxliang Date: Thu, 18 Jul 2024 14:24:23 +0800 Subject: [PATCH] refactor: don't use std::async when processing void IPC commands --- WeaselIPC/WeaselClientImpl.cpp | 41 +++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/WeaselIPC/WeaselClientImpl.cpp b/WeaselIPC/WeaselClientImpl.cpp index 2a5d90597..031bba640 100644 --- a/WeaselIPC/WeaselClientImpl.cpp +++ b/WeaselIPC/WeaselClientImpl.cpp @@ -197,18 +197,37 @@ LRESULT ClientImpl::_SendMessage(WEASEL_IPC_COMMAND Msg, DWORD lParam) { try { PipeMessage req{Msg, wParam, lParam}; - auto future = std::async(std::launch::async, - [this, &req]() { return channel.Transact(req); }); - - // wait Transact complete or overtime - if (future.wait_for(std::chrono::seconds(2)) == - std::future_status::timeout) { - // Transact overtime - return 0; - } else { - // Transact complete - return future.get(); + LRESULT ret = 0; + switch (Msg) { + case WEASEL_IPC_SHUTDOWN_SERVER: + case WEASEL_IPC_START_SESSION: + case WEASEL_IPC_END_SESSION: + case WEASEL_IPC_START_MAINTENANCE: + case WEASEL_IPC_END_MAINTENANCE: + case WEASEL_IPC_UPDATE_INPUT_POS: + case WEASEL_IPC_FOCUS_IN: + case WEASEL_IPC_FOCUS_OUT: + case WEASEL_IPC_TRAY_COMMAND: { + ret = channel.Transact(req); + break; + } + default: { + auto future = std::async(std::launch::async, [this, &req]() { + return channel.Transact(req); + }); + // wait Transact complete or overtime + if (future.wait_for(std::chrono::seconds(2)) == + std::future_status::timeout) { + // Transact overtime + ret = 0; + } else { + // Transact complete + ret = future.get(); + } + break; + } } + return ret; } catch (DWORD /* ex */) { return 0; }