diff options
author | 2021-09-14 16:25:22 -0700 | |
---|---|---|
committer | 2021-09-14 16:44:20 -0700 | |
commit | d6bca1032b1730cdd0262ba5e25190eb4a08f398 (patch) | |
tree | 8990b87cfbda1c824fcea7c0e4a765d5b86d033a | |
parent | 5252e756da5e889463c1ccce37a7e9725f25d123 (diff) |
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
-rw-r--r-- | libs/binder/FdTrigger.cpp | 15 | ||||
-rw-r--r-- | libs/binder/FdTrigger.h | 16 | ||||
-rw-r--r-- | libs/binder/RpcTransportTls.cpp | 15 |
3 files changed, 7 insertions, 39 deletions
diff --git a/libs/binder/FdTrigger.cpp b/libs/binder/FdTrigger.cpp index b197a6aa8d..ecf13dc583 100644 --- a/libs/binder/FdTrigger.cpp +++ b/libs/binder/FdTrigger.cpp @@ -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 diff --git a/libs/binder/FdTrigger.h b/libs/binder/FdTrigger.h index 5f67ba3188..a545d6cbea 100644 --- a/libs/binder/FdTrigger.h +++ b/libs/binder/FdTrigger.h @@ -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; diff --git a/libs/binder/RpcTransportTls.cpp b/libs/binder/RpcTransportTls.cpp index 63f93391e5..23088ad60e 100644 --- a/libs/binder/RpcTransportTls.cpp +++ b/libs/binder/RpcTransportTls.cpp @@ -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()); |