Add android/utils/eintr_wrapper.h
Add a new Android-specific header that defines two macros to
handle EINTR in a consistent way, as well as allow detecting
when a system call loops too many times and exit with a fatal
error message when that happens.
+ Unit tests.
+ Update existing code under android/ which uses to deal directly
with EINTR to use the new HANDLE_EINTR() and IGNORE_EINTR()
+ Remove EINTR checks for functions that call socket_xxx() functions
which already loop around EINTR.
Change-Id: I1d2ee64d9743a2edc506f616465ea091878db620
diff --git a/android/sync-utils.c b/android/sync-utils.c
index 4f2fd81..365d475 100644
--- a/android/sync-utils.c
+++ b/android/sync-utils.c
@@ -79,7 +79,7 @@
iolooper_free(looper);
return NULL;
}
- } else if (errno != EINTR) {
+ } else {
return NULL;
}
}
@@ -184,9 +184,7 @@
D("%s: Internal error, iolooper_is_read() not set!", __FUNCTION__);
return -1;
}
- do {
- ret = socket_recv(ssocket->fd, buf, size);
- } while( ret < 0 && errno == EINTR);
+ ret = socket_recv(ssocket->fd, buf, size);
} else if (ret == 0) {
// Timed out
errno = ETIMEDOUT;
@@ -229,10 +227,7 @@
return -1;
}
- do {
- ret = socket_send(ssocket->fd, (const char*)buf + written, size - written);
- } while( ret < 0 && errno == EINTR);
-
+ ret = socket_send(ssocket->fd, (const char*)buf + written, size - written);
if (ret > 0) {
written += ret;
} else if (ret < 0) {