From bb3c4c17c45c89d980e2f4f59f59e55d13c77334 Mon Sep 17 00:00:00 2001 From: Pieter Noordhuis Date: Wed, 1 May 2013 09:23:06 -0700 Subject: [PATCH] Make redisKeepAlive work on OSX --- fmacros.h | 4 ++++ net.c | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/fmacros.h b/fmacros.h index 21cd9cf..799c12c 100644 --- a/fmacros.h +++ b/fmacros.h @@ -13,4 +13,8 @@ #define _XOPEN_SOURCE #endif +#if __APPLE__ && __MACH__ +#define _OSX +#endif + #endif diff --git a/net.c b/net.c index bf571fc..3c07d68 100644 --- a/net.c +++ b/net.c @@ -122,6 +122,13 @@ int redisKeepAlive(redisContext *c, int interval) { return REDIS_ERR; } +#ifdef _OSX + val = interval; + if (setsockopt(fd, IPPROTO_TCP, TCP_KEEPALIVE, &val, sizeof(val)) < 0) { + __redisSetError(c,REDIS_ERR_OTHER,strerror(errno)); + return REDIS_ERR; + } +#else val = interval; if (setsockopt(fd, IPPROTO_TCP, TCP_KEEPIDLE, &val, sizeof(val)) < 0) { __redisSetError(c,REDIS_ERR_OTHER,strerror(errno)); @@ -140,6 +147,7 @@ int redisKeepAlive(redisContext *c, int interval) { __redisSetError(c,REDIS_ERR_OTHER,strerror(errno)); return REDIS_ERR; } +#endif return REDIS_OK; }