diff options
author | Ashutosh Agarwal <radsaggi@google.com> | 2024-04-17 21:16:06 +0000 |
---|---|---|
committer | Ashutosh Agarwal <radsaggi@google.com> | 2024-04-18 20:34:35 +0000 |
commit | 55d76349d2dc3dafb858db3ed8beadfbbcd32b4f (patch) | |
tree | d78b1bb7bec3b40fee13b03e54a6b512fe70155e | |
parent | 39fb2e6fdaf52da4c8dc29db59b33d7ea64969c3 (diff) | |
download | native-55d76349d2dc3dafb858db3ed8beadfbbcd32b4f.tar.gz |
Expose RpcServer::setMaxThreads in BinderRpc Rust API.
Bug: 332776171
Test: manual
Change-Id: I6b284d93c35230f99350c77dff2b7bb7ad79dd87
-rw-r--r-- | libs/binder/include_rpc_unstable/binder_rpc_unstable.hpp | 11 | ||||
-rw-r--r-- | libs/binder/libbinder_rpc_unstable.cpp | 4 | ||||
-rw-r--r-- | libs/binder/rust/rpcbinder/src/server/android.rs | 14 |
3 files changed, 29 insertions, 0 deletions
diff --git a/libs/binder/include_rpc_unstable/binder_rpc_unstable.hpp b/libs/binder/include_rpc_unstable/binder_rpc_unstable.hpp index 7d0acd1843..392ebb5b0a 100644 --- a/libs/binder/include_rpc_unstable/binder_rpc_unstable.hpp +++ b/libs/binder/include_rpc_unstable/binder_rpc_unstable.hpp @@ -73,6 +73,17 @@ void ARpcServer_setSupportedFileDescriptorTransportModes( const ARpcSession_FileDescriptorTransportMode modes[], size_t modes_len); +// Sets the maximum number of threads that the Server will use for +// incoming client connections. +// +// This must be called before adding a client session. This corresponds +// to the number of incoming connections to RpcSession objects in the +// server, which will correspond to the number of outgoing connections +// in client RpcSession objects. +// +// If this is not specified, this will be a single-threaded server. +void ARpcServer_setMaxThreads(ARpcServer* server, size_t threads); + // Runs ARpcServer_join() in a background thread. Immediately returns. void ARpcServer_start(ARpcServer* server); diff --git a/libs/binder/libbinder_rpc_unstable.cpp b/libs/binder/libbinder_rpc_unstable.cpp index cb44c58c2c..21537fc50d 100644 --- a/libs/binder/libbinder_rpc_unstable.cpp +++ b/libs/binder/libbinder_rpc_unstable.cpp @@ -167,6 +167,10 @@ void ARpcServer_setSupportedFileDescriptorTransportModes( server->setSupportedFileDescriptorTransportModes(modevec); } +void ARpcServer_setMaxThreads(ARpcServer* handle, size_t threads) { + handleToStrongPointer<RpcServer>(handle)->setMaxThreads(threads); +} + void ARpcServer_start(ARpcServer* handle) { handleToStrongPointer<RpcServer>(handle)->start(); } diff --git a/libs/binder/rust/rpcbinder/src/server/android.rs b/libs/binder/rust/rpcbinder/src/server/android.rs index ad0365b505..2ab34472a9 100644 --- a/libs/binder/rust/rpcbinder/src/server/android.rs +++ b/libs/binder/rust/rpcbinder/src/server/android.rs @@ -147,6 +147,20 @@ impl RpcServerRef { } } + /// Sets the max number of threads this Server uses for incoming client connections. + /// + /// This must be called before adding a client session. This corresponds + /// to the number of incoming connections to RpcSession objects in the + /// server, which will correspond to the number of outgoing connections + /// in client RpcSession objects. Specifically this is useful for handling + /// client-side callback connections. + /// + /// If this is not specified, this will be a single-threaded server. + pub fn set_max_threads(&self, count: usize) { + // SAFETY: RpcServerRef wraps a valid pointer to an ARpcServer. + unsafe { binder_rpc_unstable_bindgen::ARpcServer_setMaxThreads(self.as_ptr(), count) }; + } + /// Starts a new background thread and calls join(). Returns immediately. pub fn start(&self) { // SAFETY: RpcServerRef wraps a valid pointer to an ARpcServer. |