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
diff --git a/libs/binder/RpcSession.cpp b/libs/binder/RpcSession.cpp
index 771d738..0ea7619 100644
--- a/libs/binder/RpcSession.cpp
+++ b/libs/binder/RpcSession.cpp
@@ -127,7 +127,7 @@
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 @@
if (pfd[1].revents & POLLHUP) {
return false;
}
- return true;
+ return pfd[0].revents & POLLIN;
}
}
@@ -150,6 +150,8 @@
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;