diff options
author | 2021-05-20 19:46:40 +0000 | |
---|---|---|
committer | 2021-05-20 19:46:40 +0000 | |
commit | bb2cca75efdf69152fc417b75f19a0d3c072f126 (patch) | |
tree | 0a7a119fce054a489ad6143fe86aaa83e884123a | |
parent | b8a40de4f4357c2a8782e8ccc40fcb076413b3a0 (diff) | |
parent | b300550ef6fed5ce412af7c1ee0066f5445a31ef (diff) |
Merge "RpcServer::establishConnection: make static"
-rw-r--r-- | libs/binder/RpcServer.cpp | 33 | ||||
-rw-r--r-- | libs/binder/include/binder/RpcServer.h | 2 |
2 files changed, 14 insertions, 21 deletions
diff --git a/libs/binder/RpcServer.cpp b/libs/binder/RpcServer.cpp index 6dabbb0486..73facc1057 100644 --- a/libs/binder/RpcServer.cpp +++ b/libs/binder/RpcServer.cpp @@ -163,9 +163,8 @@ bool RpcServer::acceptOne() { { std::lock_guard<std::mutex> _l(mLock); - std::thread thread = - std::thread(&RpcServer::establishConnection, this, - std::move(sp<RpcServer>::fromExisting(this)), std::move(clientFd)); + std::thread thread = std::thread(&RpcServer::establishConnection, + sp<RpcServer>::fromExisting(this), std::move(clientFd)); mConnectingThreads[thread.get_id()] = std::move(thread); } @@ -199,10 +198,8 @@ size_t RpcServer::numUninitializedSessions() { } void RpcServer::establishConnection(sp<RpcServer>&& server, base::unique_fd clientFd) { - LOG_ALWAYS_FATAL_IF(this != server.get(), "Must pass same ownership object"); - // TODO(b/183988761): cannot trust this simple ID - LOG_ALWAYS_FATAL_IF(!mAgreedExperimental, "no!"); + LOG_ALWAYS_FATAL_IF(!server->mAgreedExperimental, "no!"); bool idValid = true; int32_t id; if (sizeof(id) != read(clientFd.get(), &id, sizeof(id))) { @@ -213,30 +210,30 @@ void RpcServer::establishConnection(sp<RpcServer>&& server, base::unique_fd clie std::thread thisThread; sp<RpcSession> session; { - std::lock_guard<std::mutex> _l(mLock); + std::lock_guard<std::mutex> _l(server->mLock); - auto threadId = mConnectingThreads.find(std::this_thread::get_id()); - LOG_ALWAYS_FATAL_IF(threadId == mConnectingThreads.end(), + auto threadId = server->mConnectingThreads.find(std::this_thread::get_id()); + LOG_ALWAYS_FATAL_IF(threadId == server->mConnectingThreads.end(), "Must establish connection on owned thread"); thisThread = std::move(threadId->second); ScopeGuard detachGuard = [&]() { thisThread.detach(); }; - mConnectingThreads.erase(threadId); + server->mConnectingThreads.erase(threadId); if (!idValid) { return; } if (id == RPC_SESSION_ID_NEW) { - LOG_ALWAYS_FATAL_IF(mSessionIdCounter >= INT32_MAX, "Out of session IDs"); - mSessionIdCounter++; + LOG_ALWAYS_FATAL_IF(server->mSessionIdCounter >= INT32_MAX, "Out of session IDs"); + server->mSessionIdCounter++; session = RpcSession::make(); - session->setForServer(wp<RpcServer>::fromExisting(this), mSessionIdCounter); + session->setForServer(wp<RpcServer>(server), server->mSessionIdCounter); - mSessions[mSessionIdCounter] = session; + server->mSessions[server->mSessionIdCounter] = session; } else { - auto it = mSessions.find(id); - if (it == mSessions.end()) { + auto it = server->mSessions.find(id); + if (it == server->mSessions.end()) { ALOGE("Cannot add thread, no record of session with ID %d", id); return; } @@ -249,10 +246,6 @@ void RpcServer::establishConnection(sp<RpcServer>&& server, base::unique_fd clie // avoid strong cycle server = nullptr; - // - // - // DO NOT ACCESS MEMBER VARIABLES BELOW - // session->join(std::move(clientFd)); } diff --git a/libs/binder/include/binder/RpcServer.h b/libs/binder/include/binder/RpcServer.h index 365bed6453..f76ecc20cd 100644 --- a/libs/binder/include/binder/RpcServer.h +++ b/libs/binder/include/binder/RpcServer.h @@ -150,7 +150,7 @@ private: friend sp<RpcServer>; RpcServer(); - void establishConnection(sp<RpcServer>&& session, base::unique_fd clientFd); + static void establishConnection(sp<RpcServer>&& server, base::unique_fd clientFd); bool setupSocketServer(const RpcSocketAddress& address); [[nodiscard]] bool acceptOne(); |