Fix use of select() instead of poll() (#6477)

* Fix Arrow poll() patch

- Negative timeout for poll() was not translated to infinite timeout for select()
- Only use select() on Windows, as other systems limit the range of the file descriptors

* Apply poll() -> select() patch to Redis's ae.c as well
This commit is contained in:
mehrdadn
2019-12-17 02:33:37 -08:00
committed by Philipp Moritz
parent 166560e428
commit 9d6e03aba0
3 changed files with 74 additions and 11 deletions
+1
View File
@@ -78,6 +78,7 @@ def ray_deps_setup():
sha256 = "8e5997b447b1afdd1efd33731968484d2fe71c271fa7f1cd6b2476367e964e0e",
patches = [
"//thirdparty/patches:hiredis-async-include-dict.patch",
"//thirdparty/patches:redis-windows-poll.patch",
],
)
+18 -11
View File
@@ -1,19 +1,13 @@
diff --git cpp/src/plasma/thirdparty/ae/ae.c cpp/src/plasma/thirdparty/ae/ae.c
--- cpp/src/plasma/thirdparty/ae/ae.c
+++ cpp/src/plasma/thirdparty/ae/ae.c
@@ -428,19 +428,33 @@ int aeProcessEvents(aeEventLoop *eventLoop, int flags)
@@ -428,20 +428,43 @@ int aeProcessEvents(aeEventLoop *eventLoop, int flags)
/* Wait for milliseconds until the given file descriptor becomes
* writable/readable/exception */
int aeWait(int fd, int mask, long long milliseconds) {
- struct pollfd pfd;
+ int retmask = 0, retval;
+ short revents = 0;
+ struct timeval tv = { milliseconds / 1000, (milliseconds % 1000) * 1000 };
int retmask = 0, retval;
- memset(&pfd, 0, sizeof(pfd));
- pfd.fd = fd;
- if (mask & AE_READABLE) pfd.events |= POLLIN;
- if (mask & AE_WRITABLE) pfd.events |= POLLOUT;
+#ifdef _WINSOCKAPI_
+ fd_set rset, wset;
+ FD_ZERO(&rset);
+ FD_ZERO(&wset);
@@ -22,8 +16,8 @@ diff --git cpp/src/plasma/thirdparty/ae/ae.c cpp/src/plasma/thirdparty/ae/ae.c
+ } else if (mask & AE_WRITABLE) {
+ FD_SET(fd, &wset);
+ }
+
+ if ((retval = select(fd + 1, &rset, &wset, NULL, &tv)) > 0) {
+ struct timeval tv = { milliseconds / 1000, (milliseconds % 1000) * 1000 };
+ if ((retval = select(fd + 1, &rset, &wset, NULL, milliseconds >= 0 ? &tv : NULL)) > 0) {
+ if (FD_ISSET(fd, &rset)) {
+ revents |= POLLIN;
+ }
@@ -31,12 +25,23 @@ diff --git cpp/src/plasma/thirdparty/ae/ae.c cpp/src/plasma/thirdparty/ae/ae.c
+ revents |= POLLOUT;
+ }
+ }
+#else
struct pollfd pfd;
- int retmask = 0, retval;
memset(&pfd, 0, sizeof(pfd));
pfd.fd = fd;
if (mask & AE_READABLE) pfd.events |= POLLIN;
if (mask & AE_WRITABLE) pfd.events |= POLLOUT;
+ retval = poll(&pfd, 1, milliseconds);
+ revents = pfd.revents;
- if ((retval = poll(&pfd, 1, milliseconds))== 1) {
- if (pfd.revents & POLLIN) retmask |= AE_READABLE;
- if (pfd.revents & POLLOUT) retmask |= AE_WRITABLE;
- if (pfd.revents & POLLERR) retmask |= AE_WRITABLE;
- if (pfd.revents & POLLHUP) retmask |= AE_WRITABLE;
+#endif
+ if (retval== 1) {
+ if (revents & POLLIN) retmask |= AE_READABLE;
+ if (revents & POLLOUT) retmask |= AE_WRITABLE;
@@ -45,4 +50,6 @@ diff --git cpp/src/plasma/thirdparty/ae/ae.c cpp/src/plasma/thirdparty/ae/ae.c
return retmask;
} else {
return retval;
}
}
--
+55
View File
@@ -0,0 +1,55 @@
diff --git src/ae.c src/ae.c
--- src/ae.c
+++ src/ae.c
@@ -474,21 +474,44 @@ int aeProcessEvents(aeEventLoop *eventLoop, int flags)
/* Wait for milliseconds until the given file descriptor becomes
* writable/readable/exception */
int aeWait(int fd, int mask, long long milliseconds) {
+ int retmask = 0, retval;
+ short revents = 0;
+#ifdef _WINSOCKAPI_
+ fd_set rset, wset;
+ FD_ZERO(&rset);
+ FD_ZERO(&wset);
+ if (mask & AE_READABLE) {
+ FD_SET(fd, &rset);
+ } else if (mask & AE_WRITABLE) {
+ FD_SET(fd, &wset);
+ }
+ struct timeval tv = { milliseconds / 1000, (milliseconds % 1000) * 1000 };
+ if ((retval = select(fd + 1, &rset, &wset, NULL, milliseconds >= 0 ? &tv : NULL)) > 0) {
+ if (FD_ISSET(fd, &rset)) {
+ revents |= POLLIN;
+ }
+ if (FD_ISSET(fd, &wset)) {
+ revents |= POLLOUT;
+ }
+ }
+#else
struct pollfd pfd;
- int retmask = 0, retval;
memset(&pfd, 0, sizeof(pfd));
pfd.fd = fd;
if (mask & AE_READABLE) pfd.events |= POLLIN;
if (mask & AE_WRITABLE) pfd.events |= POLLOUT;
+ retval = poll(&pfd, 1, milliseconds);
+ revents = pfd.revents;
- if ((retval = poll(&pfd, 1, milliseconds))== 1) {
- if (pfd.revents & POLLIN) retmask |= AE_READABLE;
- if (pfd.revents & POLLOUT) retmask |= AE_WRITABLE;
- if (pfd.revents & POLLERR) retmask |= AE_WRITABLE;
- if (pfd.revents & POLLHUP) retmask |= AE_WRITABLE;
+#endif
+ if (retval== 1) {
+ if (revents & POLLIN) retmask |= AE_READABLE;
+ if (revents & POLLOUT) retmask |= AE_WRITABLE;
+ if (revents & POLLERR) retmask |= AE_WRITABLE;
+ if (revents & POLLHUP) retmask |= AE_WRITABLE;
return retmask;
} else {
return retval;
}
}
--