mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-21 01:01:43 +00:00
Solve some safety issues with RPCs (#1127)
Java would never properly dispose, and C++'s were easy to respond after disposing. We now return a bool if the call was successful or not.
This commit is contained in:
committed by
Peter Johnson
parent
6aebba5452
commit
8eafe7f325
@@ -35,14 +35,15 @@ void RpcServer::ProcessRpc(unsigned int local_id, unsigned int call_uid,
|
||||
send_response);
|
||||
}
|
||||
|
||||
void RpcServer::PostRpcResponse(unsigned int local_id, unsigned int call_uid,
|
||||
bool RpcServer::PostRpcResponse(unsigned int local_id, unsigned int call_uid,
|
||||
wpi::StringRef result) {
|
||||
auto thr = GetThread();
|
||||
auto i = thr->m_response_map.find(impl::RpcIdPair{local_id, call_uid});
|
||||
if (i == thr->m_response_map.end()) {
|
||||
WARNING("posting RPC response to nonexistent call (or duplicate response)");
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
(i->getSecond())(result);
|
||||
thr->m_response_map.erase(i);
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user