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

Commit 264075c0 authored by Priyanka Advani (xWF)'s avatar Priyanka Advani (xWF) Committed by Android (Google) Code Review
Browse files

Revert "Refactors client acceptance logic in RpcServer::join"

Revert submission 34231615

Reason for revert: Droidmonitor created revert due to b/428745402. Will be verifying through ABTD before submission.

Fix: 428745402

Reverted changes: /q/submissionid:34231615

Change-Id: I31cd8cb56d47654d4ea03695ac5623adfef4982a
parent da5e6078
Loading
Loading
Loading
Loading
+37 −43
Original line number Diff line number Diff line
@@ -273,62 +273,56 @@ void RpcServer::join() {

    status_t status;
    while ((status = mShutdownTrigger->triggerablePoll(mServer, POLLIN)) == OK) {
        status = acceptConnection(RpcSession::join);
        if (status == DEAD_OBJECT) {
            break;
        }
    }
    LOG_RPC_DETAIL("RpcServer::join exiting with %s", statusToString(status).c_str());

    if constexpr (kEnableRpcThreads) {
        RpcMutexLockGuard _l(mLock);
        mJoinThreadRunning = false;
    } else {
        // Multi-threaded builds clear this in shutdown(), but we need it valid
        // so the loop above exits cleanly
        mShutdownTrigger = nullptr;
    }
    mShutdownCv.notify_all();
}

status_t RpcServer::acceptConnection(
        std::function<void(sp<RpcSession>&&, RpcSession::PreJoinSetupResult&&)>&& joinFn) {
    RpcTransportFd clientFd;
        std::array<uint8_t, kRpcAddressSize> addr;
        static_assert(addr.size() >= sizeof(sockaddr_storage), "kRpcAddressSize is too small");
        socklen_t addrLen = addr.size();

    status_t status;
    if ((status = mAcceptFn(*this, &clientFd)) != OK) {
        if (status != DEAD_OBJECT) {
        RpcTransportFd clientSocket;
        if ((status = mAcceptFn(*this, &clientSocket)) != OK) {
            if (status == DEAD_OBJECT) {
                break;
            } else {
                ALOGE("Accept returned error %s", statusToString(status).c_str());
                continue;
            }
        return status;
        }

    LOG_RPC_DETAIL("accept on fd %d yields fd %d", mServer.fd.get(), clientFd.fd.get());
        LOG_RPC_DETAIL("accept on fd %d yields fd %d", mServer.fd.get(), clientSocket.fd.get());

    if (getpeername(clientFd.fd.get(), reinterpret_cast<sockaddr*>(addr.data()), &addrLen)) {
        if (getpeername(clientSocket.fd.get(), reinterpret_cast<sockaddr*>(addr.data()),
                        &addrLen)) {
            ALOGE("Could not getpeername socket: %s", strerror(errno));
        return EINVAL;
            continue;
        }

        if (mConnectionFilter != nullptr && !mConnectionFilter(addr.data(), addrLen)) {
        ALOGE("Dropped client connection fd %d", clientFd.fd.get());
        return EINVAL;
            ALOGE("Dropped client connection fd %d", clientSocket.fd.get());
            continue;
        }

        {
            RpcMutexLockGuard _l(mLock);
            RpcMaybeThread thread =
                RpcMaybeThread(&RpcServer::establishConnection, sp<RpcServer>::fromExisting(this),
                               std::move(clientFd), addr, addrLen, std::move(joinFn));
                    RpcMaybeThread(&RpcServer::establishConnection,
                                   sp<RpcServer>::fromExisting(this), std::move(clientSocket), addr,
                                   addrLen, RpcSession::join);

            auto& threadRef = mConnectingThreads[thread.get_id()];
            threadRef = std::move(thread);
            rpcJoinIfSingleThreaded(threadRef);
        }
    }
    LOG_RPC_DETAIL("RpcServer::join exiting with %s", statusToString(status).c_str());

    return OK;
    if constexpr (kEnableRpcThreads) {
        RpcMutexLockGuard _l(mLock);
        mJoinThreadRunning = false;
    } else {
        // Multi-threaded builds clear this in shutdown(), but we need it valid
        // so the loop above exits cleanly
        mShutdownTrigger = nullptr;
    }
    mShutdownCv.notify_all();
}

bool RpcServer::shutdown() {
+0 −2
Original line number Diff line number Diff line
@@ -268,8 +268,6 @@ private:
    static status_t recvmsgSocketConnection(const RpcServer& server, RpcTransportFd* out);

    [[nodiscard]] status_t setupSocketServer(const RpcSocketAddress& address);
    [[nodiscard]] status_t acceptConnection(
            std::function<void(sp<RpcSession>&&, RpcSession::PreJoinSetupResult&&)>&& joinFn);

    const std::unique_ptr<RpcTransportCtx> mCtx;
    size_t mMaxThreads = 1;