blob: c6cf2c5ee842895997ea51d5ed8c5bee038ecfbf [file] [log] [blame]
Steven Moreland5553ac42020-11-11 02:14:45 +00001/*
2 * Copyright (C) 2020 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#define LOG_TAG "RpcServer"
18
Steven Moreland798e0d12021-07-14 23:19:25 +000019#include <poll.h>
Steven Moreland5553ac42020-11-11 02:14:45 +000020#include <sys/socket.h>
21#include <sys/un.h>
22
Steven Morelandf137de92021-04-24 01:54:26 +000023#include <thread>
Steven Moreland5553ac42020-11-11 02:14:45 +000024#include <vector>
25
Steven Moreland5802c2b2021-05-12 20:13:04 +000026#include <android-base/scopeguard.h>
Steven Moreland5553ac42020-11-11 02:14:45 +000027#include <binder/Parcel.h>
28#include <binder/RpcServer.h>
29#include <log/log.h>
Steven Moreland5553ac42020-11-11 02:14:45 +000030
Steven Moreland611d15f2021-05-01 01:28:27 +000031#include "RpcSocketAddress.h"
Yifan Hong1a235852021-05-13 16:07:47 -070032#include "RpcState.h"
Steven Moreland5553ac42020-11-11 02:14:45 +000033#include "RpcWireFormat.h"
34
35namespace android {
36
Steven Moreland5802c2b2021-05-12 20:13:04 +000037using base::ScopeGuard;
Steven Moreland611d15f2021-05-01 01:28:27 +000038using base::unique_fd;
39
Steven Moreland5553ac42020-11-11 02:14:45 +000040RpcServer::RpcServer() {}
Yifan Hong436f0e62021-05-19 15:25:34 -070041RpcServer::~RpcServer() {
42 (void)shutdown();
43}
Steven Moreland5553ac42020-11-11 02:14:45 +000044
45sp<RpcServer> RpcServer::make() {
Steven Moreland1a3a8ef2021-04-02 02:52:46 +000046 return sp<RpcServer>::make();
Steven Moreland5553ac42020-11-11 02:14:45 +000047}
48
49void RpcServer::iUnderstandThisCodeIsExperimentalAndIWillNotUseItInProduction() {
50 mAgreedExperimental = true;
51}
52
Steven Moreland611d15f2021-05-01 01:28:27 +000053bool RpcServer::setupUnixDomainServer(const char* path) {
54 return setupSocketServer(UnixSocketAddress(path));
55}
56
Steven Moreland611d15f2021-05-01 01:28:27 +000057bool RpcServer::setupVsockServer(unsigned int port) {
58 // realizing value w/ this type at compile time to avoid ubsan abort
59 constexpr unsigned int kAnyCid = VMADDR_CID_ANY;
60
61 return setupSocketServer(VsockSocketAddress(kAnyCid, port));
62}
63
Steven Moreland611d15f2021-05-01 01:28:27 +000064bool RpcServer::setupInetServer(unsigned int port, unsigned int* assignedPort) {
65 const char* kAddr = "127.0.0.1";
66
67 if (assignedPort != nullptr) *assignedPort = 0;
68 auto aiStart = InetSocketAddress::getAddrInfo(kAddr, port);
69 if (aiStart == nullptr) return false;
70 for (auto ai = aiStart.get(); ai != nullptr; ai = ai->ai_next) {
71 InetSocketAddress socketAddress(ai->ai_addr, ai->ai_addrlen, kAddr, port);
72 if (!setupSocketServer(socketAddress)) {
73 continue;
74 }
75
76 LOG_ALWAYS_FATAL_IF(socketAddress.addr()->sa_family != AF_INET, "expecting inet");
77 sockaddr_in addr{};
78 socklen_t len = sizeof(addr);
79 if (0 != getsockname(mServer.get(), reinterpret_cast<sockaddr*>(&addr), &len)) {
80 int savedErrno = errno;
81 ALOGE("Could not getsockname at %s: %s", socketAddress.toString().c_str(),
82 strerror(savedErrno));
83 return false;
84 }
85 LOG_ALWAYS_FATAL_IF(len != sizeof(addr), "Wrong socket type: len %zu vs len %zu",
86 static_cast<size_t>(len), sizeof(addr));
87 unsigned int realPort = ntohs(addr.sin_port);
88 LOG_ALWAYS_FATAL_IF(port != 0 && realPort != port,
89 "Requesting inet server on %s but it is set up on %u.",
90 socketAddress.toString().c_str(), realPort);
91
92 if (assignedPort != nullptr) {
93 *assignedPort = realPort;
94 }
95
96 return true;
97 }
98 ALOGE("None of the socket address resolved for %s:%u can be set up as inet server.", kAddr,
99 port);
100 return false;
101}
102
Steven Morelandf137de92021-04-24 01:54:26 +0000103void RpcServer::setMaxThreads(size_t threads) {
104 LOG_ALWAYS_FATAL_IF(threads <= 0, "RpcServer is useless without threads");
Yifan Hong1a235852021-05-13 16:07:47 -0700105 LOG_ALWAYS_FATAL_IF(mJoinThreadRunning, "Cannot set max threads while running");
Steven Morelandf137de92021-04-24 01:54:26 +0000106 mMaxThreads = threads;
107}
108
109size_t RpcServer::getMaxThreads() {
110 return mMaxThreads;
Steven Moreland5553ac42020-11-11 02:14:45 +0000111}
112
113void RpcServer::setRootObject(const sp<IBinder>& binder) {
Steven Morelandebafe332021-04-24 00:24:35 +0000114 std::lock_guard<std::mutex> _l(mLock);
Yifan Hong4ffb0c72021-05-07 18:35:14 -0700115 mRootObjectWeak = mRootObject = binder;
116}
117
118void RpcServer::setRootObjectWeak(const wp<IBinder>& binder) {
119 std::lock_guard<std::mutex> _l(mLock);
120 mRootObject.clear();
121 mRootObjectWeak = binder;
Steven Moreland5553ac42020-11-11 02:14:45 +0000122}
123
124sp<IBinder> RpcServer::getRootObject() {
Steven Morelandebafe332021-04-24 00:24:35 +0000125 std::lock_guard<std::mutex> _l(mLock);
Yifan Hong4ffb0c72021-05-07 18:35:14 -0700126 bool hasWeak = mRootObjectWeak.unsafe_get();
127 sp<IBinder> ret = mRootObjectWeak.promote();
128 ALOGW_IF(hasWeak && ret == nullptr, "RpcServer root object is freed, returning nullptr");
129 return ret;
Steven Moreland5553ac42020-11-11 02:14:45 +0000130}
131
Yifan Hong326afd12021-05-19 15:24:54 -0700132static void joinRpcServer(sp<RpcServer>&& thiz) {
133 thiz->join();
134}
135
136void RpcServer::start() {
137 LOG_ALWAYS_FATAL_IF(!mAgreedExperimental, "no!");
138 std::lock_guard<std::mutex> _l(mLock);
139 LOG_ALWAYS_FATAL_IF(mJoinThread.get(), "Already started!");
140 mJoinThread = std::make_unique<std::thread>(&joinRpcServer, sp<RpcServer>::fromExisting(this));
141}
142
Steven Moreland611d15f2021-05-01 01:28:27 +0000143void RpcServer::join() {
Yifan Hong1a235852021-05-13 16:07:47 -0700144 LOG_ALWAYS_FATAL_IF(!mAgreedExperimental, "no!");
145
146 {
147 std::lock_guard<std::mutex> _l(mLock);
148 LOG_ALWAYS_FATAL_IF(!mServer.ok(), "RpcServer must be setup to join.");
149 LOG_ALWAYS_FATAL_IF(mShutdownTrigger != nullptr, "Already joined");
150 mJoinThreadRunning = true;
Steven Morelande47511f2021-05-20 00:07:41 +0000151 mShutdownTrigger = RpcSession::FdTrigger::make();
Yifan Hong1a235852021-05-13 16:07:47 -0700152 LOG_ALWAYS_FATAL_IF(mShutdownTrigger == nullptr, "Cannot create join signaler");
Steven Morelandd539fbf2021-05-05 23:40:25 +0000153 }
Yifan Hong1a235852021-05-13 16:07:47 -0700154
Steven Moreland2b4f3802021-05-22 01:46:27 +0000155 status_t status;
Steven Moreland798e0d12021-07-14 23:19:25 +0000156 while ((status = mShutdownTrigger->triggerablePoll(mServer, POLLIN)) == OK) {
Steven Moreland410325a2021-06-02 18:37:42 +0000157 unique_fd clientFd(TEMP_FAILURE_RETRY(
158 accept4(mServer.get(), nullptr, nullptr /*length*/, SOCK_CLOEXEC)));
159
160 if (clientFd < 0) {
161 ALOGE("Could not accept4 socket: %s", strerror(errno));
162 continue;
163 }
164 LOG_RPC_DETAIL("accept4 on fd %d yields fd %d", mServer.get(), clientFd.get());
165
166 {
167 std::lock_guard<std::mutex> _l(mLock);
168 std::thread thread =
169 std::thread(&RpcServer::establishConnection, sp<RpcServer>::fromExisting(this),
170 std::move(clientFd));
171 mConnectingThreads[thread.get_id()] = std::move(thread);
172 }
Yifan Hong1a235852021-05-13 16:07:47 -0700173 }
Steven Moreland2b4f3802021-05-22 01:46:27 +0000174 LOG_RPC_DETAIL("RpcServer::join exiting with %s", statusToString(status).c_str());
Yifan Hong1a235852021-05-13 16:07:47 -0700175
176 {
177 std::lock_guard<std::mutex> _l(mLock);
178 mJoinThreadRunning = false;
179 }
180 mShutdownCv.notify_all();
Steven Morelandd539fbf2021-05-05 23:40:25 +0000181}
182
Yifan Hong1a235852021-05-13 16:07:47 -0700183bool RpcServer::shutdown() {
Yifan Hong1a235852021-05-13 16:07:47 -0700184 std::unique_lock<std::mutex> _l(mLock);
Steven Moreland9d11b922021-05-20 01:22:58 +0000185 if (mShutdownTrigger == nullptr) {
Steven Moreland1c943ec2021-07-13 23:57:56 +0000186 LOG_RPC_DETAIL("Cannot shutdown. No shutdown trigger installed (already shutdown?)");
Steven Moreland9d11b922021-05-20 01:22:58 +0000187 return false;
188 }
Yifan Hong1a235852021-05-13 16:07:47 -0700189
190 mShutdownTrigger->trigger();
Steven Morelanda8b44292021-06-08 01:27:53 +0000191 for (auto& [id, session] : mSessions) {
192 (void)id;
193 session->mShutdownTrigger->trigger();
194 }
195
Steven Morelandee3f4662021-05-22 01:07:33 +0000196 while (mJoinThreadRunning || !mConnectingThreads.empty() || !mSessions.empty()) {
Steven Morelandaf4ca712021-05-24 23:22:08 +0000197 if (std::cv_status::timeout == mShutdownCv.wait_for(_l, std::chrono::seconds(1))) {
198 ALOGE("Waiting for RpcServer to shut down (1s w/o progress). Join thread running: %d, "
199 "Connecting threads: "
200 "%zu, Sessions: %zu. Is your server deadlocked?",
201 mJoinThreadRunning, mConnectingThreads.size(), mSessions.size());
202 }
Steven Moreland9d11b922021-05-20 01:22:58 +0000203 }
Yifan Hong1a235852021-05-13 16:07:47 -0700204
Yifan Hong326afd12021-05-19 15:24:54 -0700205 // At this point, we know join() is about to exit, but the thread that calls
206 // join() may not have exited yet.
207 // If RpcServer owns the join thread (aka start() is called), make sure the thread exits;
208 // otherwise ~thread() may call std::terminate(), which may crash the process.
209 // If RpcServer does not own the join thread (aka join() is called directly),
210 // then the owner of RpcServer is responsible for cleaning up that thread.
211 if (mJoinThread.get()) {
212 mJoinThread->join();
213 mJoinThread.reset();
214 }
215
Steven Moreland1c943ec2021-07-13 23:57:56 +0000216 LOG_RPC_DETAIL("Finished waiting on shutdown.");
217
Yifan Hong1a235852021-05-13 16:07:47 -0700218 mShutdownTrigger = nullptr;
219 return true;
220}
221
Steven Morelandbdb53ab2021-05-05 17:57:41 +0000222std::vector<sp<RpcSession>> RpcServer::listSessions() {
Steven Moreland611d15f2021-05-01 01:28:27 +0000223 std::lock_guard<std::mutex> _l(mLock);
Steven Morelandbdb53ab2021-05-05 17:57:41 +0000224 std::vector<sp<RpcSession>> sessions;
225 for (auto& [id, session] : mSessions) {
Steven Moreland736664b2021-05-01 04:27:25 +0000226 (void)id;
Steven Morelandbdb53ab2021-05-05 17:57:41 +0000227 sessions.push_back(session);
Steven Moreland736664b2021-05-01 04:27:25 +0000228 }
Steven Morelandbdb53ab2021-05-05 17:57:41 +0000229 return sessions;
Steven Moreland611d15f2021-05-01 01:28:27 +0000230}
231
Steven Morelandd539fbf2021-05-05 23:40:25 +0000232size_t RpcServer::numUninitializedSessions() {
233 std::lock_guard<std::mutex> _l(mLock);
234 return mConnectingThreads.size();
235}
236
Steven Morelanda63ff932021-05-12 00:03:15 +0000237void RpcServer::establishConnection(sp<RpcServer>&& server, base::unique_fd clientFd) {
Steven Morelanda63ff932021-05-12 00:03:15 +0000238 // TODO(b/183988761): cannot trust this simple ID
Yifan Hongb3005502021-05-19 15:37:00 -0700239 LOG_ALWAYS_FATAL_IF(!server->mAgreedExperimental, "no!");
Steven Moreland9d11b922021-05-20 01:22:58 +0000240
241 // mShutdownTrigger can only be cleared once connection threads have joined.
242 // It must be set before this thread is started
243 LOG_ALWAYS_FATAL_IF(server->mShutdownTrigger == nullptr);
244
Steven Moreland659416d2021-05-11 00:47:50 +0000245 RpcConnectionHeader header;
246 status_t status = server->mShutdownTrigger->interruptableReadFully(clientFd.get(), &header,
247 sizeof(header));
Steven Moreland2b4f3802021-05-22 01:46:27 +0000248 bool idValid = status == OK;
Steven Moreland9d11b922021-05-20 01:22:58 +0000249 if (!idValid) {
Steven Moreland2b4f3802021-05-22 01:46:27 +0000250 ALOGE("Failed to read ID for client connecting to RPC server: %s",
251 statusToString(status).c_str());
252 // still need to cleanup before we can return
Steven Morelanda63ff932021-05-12 00:03:15 +0000253 }
Steven Moreland1b304292021-07-15 22:59:34 +0000254 bool incoming = header.options & RPC_CONNECTION_OPTION_INCOMING;
Steven Morelanda63ff932021-05-12 00:03:15 +0000255
256 std::thread thisThread;
257 sp<RpcSession> session;
258 {
Steven Moreland9d11b922021-05-20 01:22:58 +0000259 std::unique_lock<std::mutex> _l(server->mLock);
Steven Morelanda63ff932021-05-12 00:03:15 +0000260
Yifan Hongb3005502021-05-19 15:37:00 -0700261 auto threadId = server->mConnectingThreads.find(std::this_thread::get_id());
262 LOG_ALWAYS_FATAL_IF(threadId == server->mConnectingThreads.end(),
Steven Morelanda63ff932021-05-12 00:03:15 +0000263 "Must establish connection on owned thread");
264 thisThread = std::move(threadId->second);
Steven Morelandadc5dca2021-05-25 02:06:03 +0000265 ScopeGuard detachGuard = [&]() {
266 thisThread.detach();
Steven Moreland9d11b922021-05-20 01:22:58 +0000267 _l.unlock();
268 server->mShutdownCv.notify_all();
269 };
Steven Morelandadc5dca2021-05-25 02:06:03 +0000270 server->mConnectingThreads.erase(threadId);
Steven Moreland9d11b922021-05-20 01:22:58 +0000271
Steven Morelanda8b44292021-06-08 01:27:53 +0000272 if (!idValid || server->mShutdownTrigger->isTriggered()) {
Steven Moreland5802c2b2021-05-12 20:13:04 +0000273 return;
274 }
275
Steven Moreland01a6bad2021-06-11 00:59:20 +0000276 RpcAddress sessionId = RpcAddress::fromRawEmbedded(&header.sessionId);
277
278 if (sessionId.isZero()) {
Steven Moreland1b304292021-07-15 22:59:34 +0000279 if (incoming) {
280 ALOGE("Cannot create a new session with an incoming connection, would leak");
Steven Moreland659416d2021-05-11 00:47:50 +0000281 return;
282 }
283
Yifan Hong6fe19632021-06-24 15:50:12 -0700284 sessionId = RpcAddress::zero();
Steven Moreland01a6bad2021-06-11 00:59:20 +0000285 size_t tries = 0;
286 do {
287 // don't block if there is some entropy issue
288 if (tries++ > 5) {
289 ALOGE("Cannot find new address: %s", sessionId.toString().c_str());
290 return;
291 }
292
293 sessionId = RpcAddress::random(true /*forServer*/);
294 } while (server->mSessions.end() != server->mSessions.find(sessionId));
Steven Morelanda63ff932021-05-12 00:03:15 +0000295
296 session = RpcSession::make();
Steven Moreland103424e2021-06-02 18:16:19 +0000297 session->setMaxThreads(server->mMaxThreads);
Steven Morelanda8b44292021-06-08 01:27:53 +0000298 if (!session->setForServer(server,
299 sp<RpcServer::EventListener>::fromExisting(
300 static_cast<RpcServer::EventListener*>(
301 server.get())),
Steven Moreland01a6bad2021-06-11 00:59:20 +0000302 sessionId)) {
Steven Morelanda8b44292021-06-08 01:27:53 +0000303 ALOGE("Failed to attach server to session");
304 return;
305 }
Steven Morelanda63ff932021-05-12 00:03:15 +0000306
Steven Moreland01a6bad2021-06-11 00:59:20 +0000307 server->mSessions[sessionId] = session;
Steven Morelanda63ff932021-05-12 00:03:15 +0000308 } else {
Steven Moreland01a6bad2021-06-11 00:59:20 +0000309 auto it = server->mSessions.find(sessionId);
Yifan Hongb3005502021-05-19 15:37:00 -0700310 if (it == server->mSessions.end()) {
Steven Moreland01a6bad2021-06-11 00:59:20 +0000311 ALOGE("Cannot add thread, no record of session with ID %s",
312 sessionId.toString().c_str());
Steven Morelanda63ff932021-05-12 00:03:15 +0000313 return;
314 }
315 session = it->second;
316 }
Steven Moreland5802c2b2021-05-12 20:13:04 +0000317
Steven Moreland1b304292021-07-15 22:59:34 +0000318 if (incoming) {
Steven Morelandb86e26b2021-06-12 00:35:58 +0000319 LOG_ALWAYS_FATAL_IF(!session->addOutgoingConnection(std::move(clientFd), true),
Steven Moreland659416d2021-05-11 00:47:50 +0000320 "server state must already be initialized");
321 return;
322 }
323
Steven Moreland5802c2b2021-05-12 20:13:04 +0000324 detachGuard.Disable();
Steven Morelandc88b7fc2021-06-10 00:40:39 +0000325 session->preJoinThreadOwnership(std::move(thisThread));
Steven Morelanda63ff932021-05-12 00:03:15 +0000326 }
327
Steven Morelandc88b7fc2021-06-10 00:40:39 +0000328 auto setupResult = session->preJoinSetup(std::move(clientFd));
329
Steven Morelanda63ff932021-05-12 00:03:15 +0000330 // avoid strong cycle
331 server = nullptr;
Steven Morelanda63ff932021-05-12 00:03:15 +0000332
Steven Morelandc88b7fc2021-06-10 00:40:39 +0000333 RpcSession::join(std::move(session), std::move(setupResult));
Steven Morelanda63ff932021-05-12 00:03:15 +0000334}
335
Steven Moreland611d15f2021-05-01 01:28:27 +0000336bool RpcServer::setupSocketServer(const RpcSocketAddress& addr) {
Steven Moreland704fc1a2021-05-04 23:13:14 +0000337 LOG_RPC_DETAIL("Setting up socket server %s", addr.toString().c_str());
Yifan Hong0eb5a672021-05-12 18:00:25 -0700338 LOG_ALWAYS_FATAL_IF(hasServer(), "Each RpcServer can only have one server.");
Steven Moreland611d15f2021-05-01 01:28:27 +0000339
340 unique_fd serverFd(
341 TEMP_FAILURE_RETRY(socket(addr.addr()->sa_family, SOCK_STREAM | SOCK_CLOEXEC, 0)));
342 if (serverFd == -1) {
343 ALOGE("Could not create socket: %s", strerror(errno));
344 return false;
345 }
346
347 if (0 != TEMP_FAILURE_RETRY(bind(serverFd.get(), addr.addr(), addr.addrSize()))) {
348 int savedErrno = errno;
349 ALOGE("Could not bind socket at %s: %s", addr.toString().c_str(), strerror(savedErrno));
350 return false;
351 }
352
Yifan Honge96a1f12021-07-13 16:08:28 -0700353 // Right now, we create all threads at once, making accept4 slow. To avoid hanging the client,
354 // the backlog is increased to a large number.
355 // TODO(b/189955605): Once we create threads dynamically & lazily, the backlog can be reduced
356 // to 1.
357 if (0 != TEMP_FAILURE_RETRY(listen(serverFd.get(), 50 /*backlog*/))) {
Steven Moreland611d15f2021-05-01 01:28:27 +0000358 int savedErrno = errno;
359 ALOGE("Could not listen socket at %s: %s", addr.toString().c_str(), strerror(savedErrno));
360 return false;
361 }
362
Steven Moreland704fc1a2021-05-04 23:13:14 +0000363 LOG_RPC_DETAIL("Successfully setup socket server %s", addr.toString().c_str());
364
Yifan Hongc276f8d2021-05-13 17:13:44 -0700365 if (!setupExternalServer(std::move(serverFd))) {
366 ALOGE("Another thread has set up server while calling setupSocketServer. Race?");
367 return false;
368 }
Steven Moreland611d15f2021-05-01 01:28:27 +0000369 return true;
370}
371
Steven Moreland19fc9f72021-06-10 03:57:30 +0000372void RpcServer::onSessionLockedAllIncomingThreadsEnded(const sp<RpcSession>& session) {
Steven Morelandee78e762021-05-05 21:12:51 +0000373 auto id = session->mId;
374 LOG_ALWAYS_FATAL_IF(id == std::nullopt, "Server sessions must be initialized with ID");
Steven Moreland01a6bad2021-06-11 00:59:20 +0000375 LOG_RPC_DETAIL("Dropping session with address %s", id->toString().c_str());
Steven Morelandee78e762021-05-05 21:12:51 +0000376
377 std::lock_guard<std::mutex> _l(mLock);
378 auto it = mSessions.find(*id);
Steven Moreland01a6bad2021-06-11 00:59:20 +0000379 LOG_ALWAYS_FATAL_IF(it == mSessions.end(), "Bad state, unknown session id %s",
380 id->toString().c_str());
381 LOG_ALWAYS_FATAL_IF(it->second != session, "Bad state, session has id mismatch %s",
382 id->toString().c_str());
Steven Morelandee78e762021-05-05 21:12:51 +0000383 (void)mSessions.erase(it);
384}
385
Steven Moreland19fc9f72021-06-10 03:57:30 +0000386void RpcServer::onSessionIncomingThreadEnded() {
Steven Morelandee3f4662021-05-22 01:07:33 +0000387 mShutdownCv.notify_all();
388}
389
Yifan Hong0eb5a672021-05-12 18:00:25 -0700390bool RpcServer::hasServer() {
Yifan Hong00aeb762021-05-12 17:07:36 -0700391 LOG_ALWAYS_FATAL_IF(!mAgreedExperimental, "no!");
Yifan Hong0eb5a672021-05-12 18:00:25 -0700392 std::lock_guard<std::mutex> _l(mLock);
393 return mServer.ok();
394}
395
Yifan Hong00aeb762021-05-12 17:07:36 -0700396unique_fd RpcServer::releaseServer() {
397 LOG_ALWAYS_FATAL_IF(!mAgreedExperimental, "no!");
398 std::lock_guard<std::mutex> _l(mLock);
399 return std::move(mServer);
400}
401
402bool RpcServer::setupExternalServer(base::unique_fd serverFd) {
403 LOG_ALWAYS_FATAL_IF(!mAgreedExperimental, "no!");
404 std::lock_guard<std::mutex> _l(mLock);
405 if (mServer.ok()) {
406 ALOGE("Each RpcServer can only have one server.");
407 return false;
408 }
409 mServer = std::move(serverFd);
410 return true;
411}
412
Steven Moreland5553ac42020-11-11 02:14:45 +0000413} // namespace android