Handle EINTR from sendmsg/recvmsg
Bug: 38317278
Test: bit CtsHardwareTestCases:.HardwareBufferTest
Change-Id: I7994a416f274b7c7916d0866fcb827073b731ccb
diff --git a/libs/nativewindow/AHardwareBuffer.cpp b/libs/nativewindow/AHardwareBuffer.cpp
index 80c5ec2..c0602e7 100644
--- a/libs/nativewindow/AHardwareBuffer.cpp
+++ b/libs/nativewindow/AHardwareBuffer.cpp
@@ -179,12 +179,17 @@
memcpy(fdData, fds.get(), sizeof(int) * fdCount);
msg.msg_controllen = cmsg->cmsg_len;
- int result = sendmsg(socketFd, &msg, 0);
- if (result <= 0) {
+ int result;
+ do {
+ result = sendmsg(socketFd, &msg, 0);
+ } while (result == -1 && errno == EINTR);
+ if (result == -1) {
+ result = errno;
ALOGE("Error writing AHardwareBuffer to socket: error %#x (%s)",
- result, strerror(errno));
- return result;
+ result, strerror(result));
+ return -result;
}
+
return NO_ERROR;
}
@@ -206,11 +211,15 @@
.msg_iovlen = 1,
};
- int result = recvmsg(socketFd, &msg, 0);
- if (result <= 0) {
+ int result;
+ do {
+ result = recvmsg(socketFd, &msg, 0);
+ } while (result == -1 && errno == EINTR);
+ if (result == -1) {
+ result = errno;
ALOGE("Error reading AHardwareBuffer from socket: error %#x (%s)",
- result, strerror(errno));
- return result;
+ result, strerror(result));
+ return -result;
}
if (msg.msg_iovlen != 1) {