ray/thirdparty/patches/hiredis-windows-sockets.patch
mehrdadn b4030cdbbe
File HANDLE/descriptor translation layer for Windows (#7657)
* Use TCP sockets on Windows with custom HANDLE <-> FD translation layer

* Get Plasma working on Windows

Co-authored-by: Mehrdad <noreply@github.com>
2020-03-23 21:08:25 -07:00

58 lines
1.8 KiB
Diff

diff --git deps/hiredis/hiredis.c deps/hiredis/hiredis.c
--- deps/hiredis/hiredis.c
+++ deps/hiredis/hiredis.c
@@ -620,1 +620,1 @@
- close(c->fd);
+ redisContextCloseFd(c);
@@ -648,1 +648,1 @@
- close(c->fd);
+ redisContextCloseFd(c);
diff --git deps/hiredis/net.h deps/hiredis/net.h
--- deps/hiredis/net.h
+++ deps/hiredis/net.h
@@ -44,1 +44,2 @@
+void redisContextCloseFd(redisContext *c);
int redisContextConnectTcp(redisContext *c, const char *addr, int port, const struct timeval *timeout);
diff --git deps/hiredis/net.c deps/hiredis/net.c
--- deps/hiredis/net.c
+++ deps/hiredis/net.c
@@ -60,1 +60,1 @@
-static void redisContextCloseFd(redisContext *c) {
+void redisContextCloseFd(redisContext *c) {
@@ -102,24 +102,33 @@
static int redisSetBlocking(redisContext *c, int blocking) {
int flags;
- /* Set the socket nonblocking.
+ /* Set the socket nonblocking. */
+#ifdef _WINSOCKAPI_
+ unsigned long value = !blocking;
+ if (ioctlsocket(c->fd, FIONBIO, &value) == SOCKET_ERROR) {
+ __redisSetErrorFromErrno(c,REDIS_ERR_IO,"ioctlsocket(FIONBIO)");
+ redisContextCloseFd(c);
+ return REDIS_ERR;
+ }
+#else
- * Note that fcntl(2) for F_GETFL and F_SETFL can't be
+ /* Note that fcntl(2) for F_GETFL and F_SETFL can't be
* interrupted by a signal. */
if ((flags = fcntl(c->fd, F_GETFL)) == -1) {
__redisSetErrorFromErrno(c,REDIS_ERR_IO,"fcntl(F_GETFL)");
redisContextCloseFd(c);
return REDIS_ERR;
}
if (blocking)
flags &= ~O_NONBLOCK;
else
flags |= O_NONBLOCK;
if (fcntl(c->fd, F_SETFL, flags) == -1) {
__redisSetErrorFromErrno(c,REDIS_ERR_IO,"fcntl(F_SETFL)");
redisContextCloseFd(c);
return REDIS_ERR;
}
+#endif
return REDIS_OK;
}
--