Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 287c8e85 authored by Inseob Kim's avatar Inseob Kim Committed by Automerger Merge Worker
Browse files

Add support for preconnected RPC client am: e12fccc4 am: 0a6d2102 am: 9880e94d

Original change: https://android-review.googlesource.com/c/platform/frameworks/native/+/1816819

Change-Id: I6a2f974dcca5d96d4f5a70c423f4e5f13474f325
parents 75d947de 9880e94d
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -23,4 +23,13 @@ struct AIBinder;
bool RunRpcServer(AIBinder* service, unsigned int port);
AIBinder* RpcClient(unsigned int cid, unsigned int port);

// Connect to an RPC server with preconnected file descriptors.
//
// requestFd should connect to the server and return a valid file descriptor, or
// -1 if connection fails.
//
// param will be passed to requestFd. Callers can use param to pass contexts to
// the requestFd function.
AIBinder* RpcPreconnectedClient(int (*requestFd)(void* param), void* param);

}
+12 −0
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@
 */

#include <android-base/logging.h>
#include <android-base/unique_fd.h>
#include <android/binder_libbinder.h>
#include <binder/RpcServer.h>
#include <binder/RpcSession.h>
@@ -24,6 +25,7 @@ using android::RpcServer;
using android::RpcSession;
using android::status_t;
using android::statusToString;
using android::base::unique_fd;

extern "C" {

@@ -52,4 +54,14 @@ AIBinder* RpcClient(unsigned int cid, unsigned int port) {
    }
    return AIBinder_fromPlatformBinder(session->getRootObject());
}

AIBinder* RpcPreconnectedClient(int (*requestFd)(void* param), void* param) {
    auto session = RpcSession::make();
    auto request = [=] { return unique_fd{requestFd(param)}; };
    if (status_t status = session->setupPreconnectedClient(unique_fd{}, request); status != OK) {
        LOG(ERROR) << "Failed to set up vsock client. error: " << statusToString(status).c_str();
        return nullptr;
    }
    return AIBinder_fromPlatformBinder(session->getRootObject());
}
}
+1 −0
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@ LIBBINDER_RPC_UNSTABLE_SHIM { # platform-only
  global:
    RunRpcServer;
    RpcClient;
    RpcPreconnectedClient;
  local:
    *;
};