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

Commit d6bca103 authored by Steven Moreland's avatar Steven Moreland
Browse files

libbinder: RPC remove isTriggeredPolled

We can get this information in-process, so we can avoid the syscall (and
due to the way it is implemented, we also don't need locking).

Bug: 182940634
Test: binderRpcTest
Change-Id: I3a4f683f71f54972509e071f5dd349e15de54b08
parent 5252e756
Loading
Loading
Loading
Loading
+0 −15
Original line number Diff line number Diff line
@@ -59,19 +59,4 @@ status_t FdTrigger::triggerablePoll(base::borrowed_fd fd, int16_t event) {
    }
}

android::base::Result<bool> FdTrigger::isTriggeredPolled() {
    pollfd pfd{.fd = mRead.get(), .events = 0, .revents = 0};
    int ret = TEMP_FAILURE_RETRY(poll(&pfd, 1, 0));
    if (ret < 0) {
        return android::base::ErrnoError() << "FdTrigger::isTriggeredPolled: Error in poll()";
    }
    if (ret == 0) {
        return false;
    }
    if (pfd.revents & POLLHUP) {
        return true;
    }
    return android::base::Error() << "FdTrigger::isTriggeredPolled: poll() returns " << pfd.revents;
}

} // namespace android
+5 −11
Original line number Diff line number Diff line
@@ -35,7 +35,11 @@ public:
    void trigger();

    /**
     * Check whether this has been triggered by checking the write end.
     * Check whether this has been triggered by checking the write end. Note:
     * this has no internal locking, and it is inherently racey, but this is
     * okay, because if we accidentally return false when a trigger has already
     * happened, we can imagine that instead, the scheduler actually executed
     * the code which is polling isTriggered earlier.
     */
    [[nodiscard]] bool isTriggered();

@@ -50,16 +54,6 @@ public:
     */
    [[nodiscard]] status_t triggerablePoll(base::borrowed_fd fd, int16_t event);

    /**
     * Check whether this has been triggered by poll()ing the read end.
     *
     * Return:
     *   true - triggered
     *   false - not triggered
     *   error - error when polling
     */
    [[nodiscard]] android::base::Result<bool> isTriggeredPolled();

private:
    base::unique_fd mWrite;
    base::unique_fd mRead;
+2 −13
Original line number Diff line number Diff line
@@ -319,8 +319,6 @@ public:
private:
    android::base::unique_fd mSocket;
    Ssl mSsl;

    static status_t isTriggered(FdTrigger* fdTrigger);
};

// Error code is errno.
@@ -341,15 +339,6 @@ Result<size_t> RpcTransportTls::peek(void* buf, size_t size) {
    return ret;
}

status_t RpcTransportTls::isTriggered(FdTrigger* fdTrigger) {
    auto ret = fdTrigger->isTriggeredPolled();
    if (!ret.ok()) {
        ALOGE("%s: %s", __PRETTY_FUNCTION__, ret.error().message().c_str());
        return ret.error().code() == 0 ? UNKNOWN_ERROR : -ret.error().code();
    }
    return *ret ? -ECANCELED : OK;
}

status_t RpcTransportTls::interruptableWriteFully(FdTrigger* fdTrigger, const void* data,
                                                  size_t size) {
    auto buffer = reinterpret_cast<const uint8_t*>(data);
@@ -359,7 +348,7 @@ status_t RpcTransportTls::interruptableWriteFully(FdTrigger* fdTrigger, const vo

    // Before doing any I/O, check trigger once. This ensures the trigger is checked at least
    // once. The trigger is also checked via triggerablePoll() after every SSL_write().
    if (status_t status = isTriggered(fdTrigger); status != OK) return status;
    if (fdTrigger->isTriggered()) return -ECANCELED;

    while (buffer < end) {
        size_t todo = std::min<size_t>(end - buffer, std::numeric_limits<int>::max());
@@ -390,7 +379,7 @@ status_t RpcTransportTls::interruptableReadFully(FdTrigger* fdTrigger, void* dat

    // Before doing any I/O, check trigger once. This ensures the trigger is checked at least
    // once. The trigger is also checked via triggerablePoll() after every SSL_write().
    if (status_t status = isTriggered(fdTrigger); status != OK) return status;
    if (fdTrigger->isTriggered()) return -ECANCELED;

    while (buffer < end) {
        size_t todo = std::min<size_t>(end - buffer, std::numeric_limits<int>::max());