summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Treehugger Robot <treehugger-gerrit@google.com> 2021-05-14 03:26:07 +0000
committer Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> 2021-05-14 03:26:07 +0000
commitbf43a605a385c711a21eda428f81e175ee2f3e6d (patch)
tree6a1d3b249e152e311de12fe2f1dfbbdce2e1a414
parentb45e770984a431a6d0fedc7c13d4d5b8c0f45ac1 (diff)
parent410cc968875e3f3894232df7e3393f589c943b11 (diff)
Merge "Add RpcServer::hasServer" am: 60e069a155 am: 67cf7e1ecd am: 410cc96887
Original change: https://android-review.googlesource.com/c/platform/frameworks/native/+/1705664 Change-Id: I7d36f4541dd5717b932bb105fb5b08e658675395
-rw-r--r--libs/binder/RpcServer.cpp13
-rw-r--r--libs/binder/include/binder/RpcServer.h5
2 files changed, 12 insertions, 6 deletions
diff --git a/libs/binder/RpcServer.cpp b/libs/binder/RpcServer.cpp
index 3c63789648..dc10d1c524 100644
--- a/libs/binder/RpcServer.cpp
+++ b/libs/binder/RpcServer.cpp
@@ -134,7 +134,7 @@ void RpcServer::join() {
bool RpcServer::acceptOne() {
LOG_ALWAYS_FATAL_IF(!mAgreedExperimental, "no!");
- LOG_ALWAYS_FATAL_IF(mServer.get() == -1, "RpcServer must be setup to join.");
+ LOG_ALWAYS_FATAL_IF(!hasServer(), "RpcServer must be setup to join.");
unique_fd clientFd(
TEMP_FAILURE_RETRY(accept4(mServer.get(), nullptr, nullptr /*length*/, SOCK_CLOEXEC)));
@@ -232,11 +232,7 @@ void RpcServer::establishConnection(sp<RpcServer>&& server, base::unique_fd clie
bool RpcServer::setupSocketServer(const RpcSocketAddress& addr) {
LOG_RPC_DETAIL("Setting up socket server %s", addr.toString().c_str());
-
- {
- std::lock_guard<std::mutex> _l(mLock);
- LOG_ALWAYS_FATAL_IF(mServer.get() != -1, "Each RpcServer can only have one server.");
- }
+ LOG_ALWAYS_FATAL_IF(hasServer(), "Each RpcServer can only have one server.");
unique_fd serverFd(
TEMP_FAILURE_RETRY(socket(addr.addr()->sa_family, SOCK_STREAM | SOCK_CLOEXEC, 0)));
@@ -275,4 +271,9 @@ void RpcServer::onSessionTerminating(const sp<RpcSession>& session) {
(void)mSessions.erase(it);
}
+bool RpcServer::hasServer() {
+ std::lock_guard<std::mutex> _l(mLock);
+ return mServer.ok();
+}
+
} // namespace android
diff --git a/libs/binder/include/binder/RpcServer.h b/libs/binder/include/binder/RpcServer.h
index 6e2754016a..771bbe68b8 100644
--- a/libs/binder/include/binder/RpcServer.h
+++ b/libs/binder/include/binder/RpcServer.h
@@ -74,6 +74,11 @@ public:
*/
[[nodiscard]] bool setupInetServer(unsigned int port, unsigned int* assignedPort);
+ /**
+ * If setup*Server has been successful, return true. Otherwise return false.
+ */
+ [[nodiscard]] bool hasServer();
+
void iUnderstandThisCodeIsExperimentalAndIWillNotUseItInProduction();
/**