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

Commit 00a4d4d3 authored by Steven Moreland's avatar Steven Moreland Committed by Android (Google) Code Review
Browse files

Merge "RPC Binder: unify RpcState RPC error handling" into main

parents 14a2c2b7 a4bed6a9
Loading
Loading
Loading
Loading
+17 −18
Original line number Diff line number Diff line
@@ -374,6 +374,21 @@ RpcState::CommandData::CommandData(size_t size) : mSize(size) {
    mData.reset(data);
}

// all transport errors should pass through here
static inline status_t handleRpcError(const std::unique_ptr<RpcTransport>& transport,
                                      const sp<RpcSession>& session, status_t status,
                                      const char* stateContext, const char* what, int niovs) {
    if (status == DEAD_OBJECT || status == -ECONNRESET) {
        LOG_RPC_DETAIL("Failed to %s %s (%d iovs) on RpcTransport %p, error: %s", stateContext,
                       what, niovs, transport.get(), statusToString(status).c_str());
    } else {
        ALOGE("Failed to %s %s (%d iovs) on RpcTransport %p, error: %s", stateContext, what, niovs,
              transport.get(), statusToString(status).c_str());
    }
    (void)session->shutdownAndWait(false);
    return status;
}

// MUST ALWAYS SHUTDOWN ON ERROR, DUE TO CALLER CONSTRAITS
status_t RpcState::rpcSend(const sp<RpcSession::RpcConnection>& connection,
                           const sp<RpcSession>& session, const char* what, iovec* iovs, int niovs,
@@ -390,15 +405,7 @@ status_t RpcState::rpcSend(const sp<RpcSession::RpcConnection>& connection,
                                                                  iovs, niovs, altPoll,
                                                                  ancillaryFds);
        status != OK) {
        if (status == DEAD_OBJECT || status == -ECONNRESET) {
            LOG_RPC_DETAIL("Failed to write %s (%d iovs) on RpcTransport %p, error: %s", what,
                           niovs, connection->rpcTransport.get(), statusToString(status).c_str());
        } else {
            ALOGE("Failed to write %s (%d iovs) on RpcTransport %p, error: %s", what, niovs,
                  connection->rpcTransport.get(), statusToString(status).c_str());
        }
        (void)session->shutdownAndWait(false);
        return status;
        return handleRpcError(connection->rpcTransport, session, status, "write", what, niovs);
    }

    return OK;
@@ -413,15 +420,7 @@ status_t RpcState::rpcRec(const sp<RpcSession::RpcConnection>& connection,
                                                                 iovs, niovs, std::nullopt,
                                                                 ancillaryFds);
        status != OK) {
        if (status == DEAD_OBJECT || status == -ECONNRESET) {
            LOG_RPC_DETAIL("Failed to read %s (%d iovs) on RpcTransport %p, error: %s", what, niovs,
                           connection->rpcTransport.get(), statusToString(status).c_str());
        } else {
            ALOGE("Failed to read %s (%d iovs) on RpcTransport %p, error: %s", what, niovs,
                  connection->rpcTransport.get(), statusToString(status).c_str());
        }
        (void)session->shutdownAndWait(false);
        return status;
        return handleRpcError(connection->rpcTransport, session, status, "read", what, niovs);
    }

    for (int i = 0; i < niovs; i++) {