libbinder: RPC more symmetrical max threads
Now, RpcServer and RpcSession both keep track of their max threads using
the same variable, and the server can therefore request the number of
reverse connections possible.
Bug: 185167543
Test: N/A
Change-Id: Ieaff69c8c2da2faf7598aed7e862601a1fcd7a00
diff --git a/libs/binder/RpcSession.cpp b/libs/binder/RpcSession.cpp
index a3efa56..a27dff5 100644
--- a/libs/binder/RpcSession.cpp
+++ b/libs/binder/RpcSession.cpp
@@ -59,15 +59,18 @@
return sp<RpcSession>::make();
}
-void RpcSession::setMaxReverseConnections(size_t connections) {
- {
- std::lock_guard<std::mutex> _l(mMutex);
- LOG_ALWAYS_FATAL_IF(mClientConnections.size() != 0,
- "Must setup reverse connections before setting up client connections, "
- "but already has %zu clients",
- mClientConnections.size());
- }
- mMaxReverseConnections = connections;
+void RpcSession::setMaxThreads(size_t threads) {
+ std::lock_guard<std::mutex> _l(mMutex);
+ LOG_ALWAYS_FATAL_IF(!mClientConnections.empty() || !mServerConnections.empty(),
+ "Must set max threads before setting up connections, but has %zu client(s) "
+ "and %zu server(s)",
+ mClientConnections.size(), mServerConnections.size());
+ mMaxThreads = threads;
+}
+
+size_t RpcSession::getMaxThreads() {
+ std::lock_guard<std::mutex> _l(mMutex);
+ return mMaxThreads;
}
bool RpcSession::setupUnixDomainClient(const char* path) {
@@ -309,7 +312,7 @@
// requested to be set) in order to allow the other side to reliably make
// any requests at all.
- for (size_t i = 0; i < mMaxReverseConnections; i++) {
+ for (size_t i = 0; i < mMaxThreads; i++) {
if (!setupOneSocketConnection(addr, mId.value(), true /*reverse*/)) return false;
}