提交 8237c963 编写于 作者: S Simon Fels

bridge: use five second timeout for all RPC

Before we were waiting forever for a reply which never occured in some
cases due to errors when processing incoming protobuf messages we now
abort the RPC call after a timeout of five seconds to keep operational.
上级 f76c0394
......@@ -29,6 +29,10 @@
namespace fs = boost::filesystem;
namespace {
constexpr const std::chrono::milliseconds default_rpc_call_timeout{5000};
} // namespace
namespace anbox {
namespace bridge {
AndroidApiStub::AndroidApiStub() {}
......@@ -103,7 +107,9 @@ void AndroidApiStub::launch(const android::Intent &intent,
google::protobuf::NewCallback(this, &AndroidApiStub::application_launched,
c.get()));
launch_wait_handle_.wait_for_all();
launch_wait_handle_.wait_for_pending(default_rpc_call_timeout);
if (!launch_wait_handle_.has_result())
throw std::runtime_error("RPC call timed out");
if (c->response->has_error()) throw std::runtime_error(c->response->error());
}
......@@ -135,7 +141,9 @@ void AndroidApiStub::set_focused_task(const std::int32_t &id) {
google::protobuf::NewCallback(
this, &AndroidApiStub::focused_task_set, c.get()));
set_focused_task_handle_.wait_for_all();
set_focused_task_handle_.wait_for_pending(default_rpc_call_timeout);
if (!set_focused_task_handle_.has_result())
throw std::runtime_error("RPC call timed out");
if (c->response->has_error()) throw std::runtime_error(c->response->error());
}
......@@ -162,7 +170,9 @@ void AndroidApiStub::remove_task(const std::int32_t &id) {
google::protobuf::NewCallback(
this, &AndroidApiStub::task_removed, c.get()));
remove_task_handle_.wait_for_all();
remove_task_handle_.wait_for_pending(default_rpc_call_timeout);
if (!remove_task_handle_.has_result())
throw std::runtime_error("RPC call timed out");
if (c->response->has_error()) throw std::runtime_error(c->response->error());
}
......@@ -198,7 +208,9 @@ void AndroidApiStub::resize_task(const std::int32_t &id,
google::protobuf::NewCallback(
this, &AndroidApiStub::task_resized, c.get()));
resize_task_handle_.wait_for_all();
resize_task_handle_.wait_for_pending(default_rpc_call_timeout);
if (!resize_task_handle_.has_result())
throw std::runtime_error("RPC call timed out");
if (c->response->has_error()) throw std::runtime_error(c->response->error());
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册