Skip to content

Commit

Permalink
refactor: don't use std::async when processing void IPC commands
Browse files Browse the repository at this point in the history
  • Loading branch information
fxliang committed Jul 18, 2024
1 parent e2fd219 commit 60c5455
Showing 1 changed file with 30 additions and 11 deletions.
41 changes: 30 additions & 11 deletions WeaselIPC/WeaselClientImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 60c5455

Please sign in to comment.