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

Commit 0f58fb9f authored by Yifan Hong's avatar Yifan Hong
Browse files

binderRpcTest: remove Pipe class.

We don't need a wrapper class for it; just use two FDs.

Test: run it

Change-Id: I6f4f1a42f1edb093a4a9aa57ca65ee80e43601a5
parent 936fc19a
Loading
Loading
Loading
Loading
+9 −19
Original line number Diff line number Diff line
@@ -255,27 +255,17 @@ public:
};
sp<IBinder> MyBinderRpcTest::mHeldBinder;

class Pipe {
public:
    Pipe() { CHECK(android::base::Pipe(&mRead, &mWrite)); }
    Pipe(Pipe&&) = default;
    android::base::borrowed_fd readEnd() { return mRead; }
    android::base::borrowed_fd writeEnd() { return mWrite; }

private:
    android::base::unique_fd mRead;
    android::base::unique_fd mWrite;
};

class Process {
public:
    Process(Process&&) = default;
    Process(const std::function<void(Pipe*)>& f) {
    Process(const std::function<void(android::base::borrowed_fd /* writeEnd */)>& f) {
        android::base::unique_fd writeEnd;
        CHECK(android::base::Pipe(&mReadEnd, &writeEnd)) << strerror(errno);
        if (0 == (mPid = fork())) {
            // racey: assume parent doesn't crash before this is set
            prctl(PR_SET_PDEATHSIG, SIGHUP);

            f(&mPipe);
            f(writeEnd);

            exit(0);
        }
@@ -285,11 +275,11 @@ public:
            waitpid(mPid, nullptr, 0);
        }
    }
    Pipe* getPipe() { return &mPipe; }
    android::base::borrowed_fd readEnd() { return mReadEnd; }

private:
    pid_t mPid = 0;
    Pipe mPipe;
    android::base::unique_fd mReadEnd;
};

static std::string allocateSocketAddress() {
@@ -402,7 +392,7 @@ public:
        vsockPort++;

        auto ret = ProcessSession{
                .host = Process([&](Pipe* pipe) {
                .host = Process([&](android::base::borrowed_fd writeEnd) {
                    sp<RpcServer> server = RpcServer::make();

                    server->iUnderstandThisCodeIsExperimentalAndIWillNotUseItInProduction();
@@ -426,7 +416,7 @@ public:
                            LOG_ALWAYS_FATAL("Unknown socket type");
                    }

                    CHECK(android::base::WriteFully(pipe->writeEnd(), &outPort, sizeof(outPort)));
                    CHECK(android::base::WriteFully(writeEnd, &outPort, sizeof(outPort)));

                    configure(server);

@@ -439,7 +429,7 @@ public:

        // always read socket, so that we have waited for the server to start
        unsigned int outPort = 0;
        CHECK(android::base::ReadFully(ret.host.getPipe()->readEnd(), &outPort, sizeof(outPort)));
        CHECK(android::base::ReadFully(ret.host.readEnd(), &outPort, sizeof(outPort)));
        if (socketType == SocketType::INET) {
            CHECK_NE(0, outPort);
        }