rpc_binder: Refactor C/Rust bindings to control server lifetime
The RpcServer C/Rust bindings have been written such that the calling thread blocks until the server has returned. This is technically not necessary because the server runs in a different thread anyway, and it required a callback function to notify the caller that the server is ready. This construct complicated the caller code. Another limitation of this construct is that it is impossible for the caller to shutdown the server when it's not needed anymore. The only way of killing it is to kill either the thread or the process, neither of which does proper cleanup. To address this, refactor the C bindings to return an opaque handle for the created RpcServer, and only destroy the object when ARpcServer_shutdown(handle) is called. The caller can also invoke ARpcServer_join(handle) to join the server thread. The Rust bindings are modified accordingly - the handle is wrapped in a RpcServer struct. RunVsockRpcServerWithFactory and the corresponding Rust wrapper are left unchanged. The lifetime of the factory reference is quite complex and the only user of this function will be removed soon. When that happens, we will remove RunVsockRpcServerWithFactory as well. Test: atest -p packages/modules/Virtualization:avf-presubmit Change-Id: I98fa0a97eb169de95ef8649c43f37a9c7c4cd96e
Loading
Please register or sign in to comment