Make redisKeepAlive work on OSX

This commit is contained in:
Pieter Noordhuis 2013-05-01 09:23:06 -07:00
parent 9dff5105fc
commit bb3c4c17c4
2 changed files with 12 additions and 0 deletions

View File

@ -13,4 +13,8 @@
#define _XOPEN_SOURCE
#endif
#if __APPLE__ && __MACH__
#define _OSX
#endif
#endif

8
net.c
View File

@ -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;
}