diff options
author | 2021-05-20 00:32:47 +0000 | |
---|---|---|
committer | 2021-05-20 00:36:51 +0000 | |
commit | 4ec3c43c8a9f16f90ab5830c4aa1e238a0c248cf (patch) | |
tree | 594dca426c714357e6deebff1f5f14774e509193 /libs/binder/RpcSession.cpp | |
parent | e47511f808818fca08962fa268700ca3d31224a3 (diff) |
libbinder: FdTrigger encapsulate poll
So we can use this in other places.
Bug: 185167543
Test: binderRpcTest
Change-Id: Ie8012b1c8dcea035bc8d0f14af2bd2ddbb197d89
Diffstat (limited to 'libs/binder/RpcSession.cpp')
-rw-r--r-- | libs/binder/RpcSession.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/libs/binder/RpcSession.cpp b/libs/binder/RpcSession.cpp index 4efa6bb1a9..ea82f36400 100644 --- a/libs/binder/RpcSession.cpp +++ b/libs/binder/RpcSession.cpp @@ -19,10 +19,12 @@ #include <binder/RpcSession.h> #include <inttypes.h> +#include <poll.h> #include <unistd.h> #include <string_view> +#include <android-base/macros.h> #include <binder/Parcel.h> #include <binder/RpcServer.h> #include <binder/Stability.h> @@ -123,6 +125,25 @@ void RpcSession::FdTrigger::trigger() { mWrite.reset(); } +bool RpcSession::FdTrigger::triggerablePollRead(base::borrowed_fd fd) { + while (true) { + pollfd pfd[]{{.fd = fd.get(), .events = POLLIN, .revents = 0}, + {.fd = mRead.get(), .events = POLLHUP, .revents = 0}}; + int ret = TEMP_FAILURE_RETRY(poll(pfd, arraysize(pfd), -1)); + if (ret < 0) { + ALOGE("Could not poll: %s", strerror(errno)); + continue; + } + if (ret == 0) { + continue; + } + if (pfd[1].revents & POLLHUP) { + return false; + } + return true; + } +} + status_t RpcSession::readId() { { std::lock_guard<std::mutex> _l(mMutex); |