diff options
author | 2021-05-22 00:24:29 +0000 | |
---|---|---|
committer | 2021-05-22 01:32:01 +0000 | |
commit | dfe3be98c64c24f52ee5dc656fb1c3318ce6aa25 (patch) | |
tree | 341560d8484855a5d4a82f38209c3a978eba1823 | |
parent | 6b5669673deb6406d68ef8aebaee15e32163420e (diff) |
libbinder: FdTrigger detect read POLLHUP/EOF
> Did you just hang up on me?
>> I don't know, did it sound like this?
*click*
When talking to a service, and it hangs up, don't just stand there, do
something!
Bug: 185167543
Test: binderRpcTest
Change-Id: I5cc00debffad2eb2cca6fabdcf3f55bb69514cb9
-rw-r--r-- | libs/binder/RpcSession.cpp | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/libs/binder/RpcSession.cpp b/libs/binder/RpcSession.cpp index 771d738579..0ea761918e 100644 --- a/libs/binder/RpcSession.cpp +++ b/libs/binder/RpcSession.cpp @@ -127,7 +127,7 @@ void RpcSession::FdTrigger::trigger() { bool RpcSession::FdTrigger::triggerablePollRead(base::borrowed_fd fd) { while (true) { - pollfd pfd[]{{.fd = fd.get(), .events = POLLIN, .revents = 0}, + pollfd pfd[]{{.fd = fd.get(), .events = POLLIN | POLLHUP, .revents = 0}, {.fd = mRead.get(), .events = POLLHUP, .revents = 0}}; int ret = TEMP_FAILURE_RETRY(poll(pfd, arraysize(pfd), -1)); if (ret < 0) { @@ -140,7 +140,7 @@ bool RpcSession::FdTrigger::triggerablePollRead(base::borrowed_fd fd) { if (pfd[1].revents & POLLHUP) { return false; } - return true; + return pfd[0].revents & POLLIN; } } @@ -150,6 +150,8 @@ bool RpcSession::FdTrigger::interruptableRecv(base::borrowed_fd fd, void* data, while (triggerablePollRead(fd)) { ssize_t readSize = TEMP_FAILURE_RETRY(recv(fd.get(), buffer, end - buffer, MSG_NOSIGNAL)); + if (readSize == 0) return false; // EOF + if (readSize < 0) { ALOGE("Failed to read %s", strerror(errno)); return false; |