redis / hiredis-rb

Ruby wrapper for hiredis
BSD 3-Clause "New" or "Revised" License
320 stars 90 forks source link

redisKeepAlive cause compile errors in solaris. #16

Closed youngwolf-project closed 10 years ago

youngwolf-project commented 10 years ago

I have presented a workaround:

int redisKeepAlive(redisContext *c, int interval) { int val = 1; int fd = c->fd;

if (setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &val, sizeof(val)) == -1){
    __redisSetError(c,REDIS_ERR_OTHER,strerror(errno));
    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

#if defined(__sun) && defined(__SVR4)
#else
val = interval;
if (setsockopt(fd, IPPROTO_TCP, TCP_KEEPIDLE, &val, sizeof(val)) < 0) {
    __redisSetError(c,REDIS_ERR_OTHER,strerror(errno));
    return REDIS_ERR;
}

val = interval/3;
if (val == 0) val = 1;
if (setsockopt(fd, IPPROTO_TCP, TCP_KEEPINTVL, &val, sizeof(val)) < 0) {
    __redisSetError(c,REDIS_ERR_OTHER,strerror(errno));
    return REDIS_ERR;
}

val = 3;
if (setsockopt(fd, IPPROTO_TCP, TCP_KEEPCNT, &val, sizeof(val)) < 0) {
    __redisSetError(c,REDIS_ERR_OTHER,strerror(errno));
    return REDIS_ERR;
}
#endif

endif

return REDIS_OK;

}

youngwolf-project commented 10 years ago

Sorry, this issue is for hiredis, not for hiredis-rb.