summaryrefslogtreecommitdiff
path: root/net.c
diff options
context:
space:
mode:
Diffstat (limited to 'net.c')
-rw-r--r--net.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/net.c b/net.c
index d4a92ab..75cbe54 100644
--- a/net.c
+++ b/net.c
@@ -98,6 +98,20 @@ static int redisSetTcpNoDelay(redisContext *c, int fd) {
return REDIS_OK;
}
+int redisContextSetTimeout(redisContext *c, struct timeval tv) {
+ if (setsockopt(c->fd,SOL_SOCKET,SO_RCVTIMEO,&tv,sizeof(tv)) == -1) {
+ __redisSetError(c,REDIS_ERR_IO,
+ sdscatprintf(sdsempty(), "setsockopt(SO_RCVTIMEO): %s", strerror(errno)));
+ return REDIS_ERR;
+ }
+ if (setsockopt(c->fd,SOL_SOCKET,SO_SNDTIMEO,&tv,sizeof(tv)) == -1) {
+ __redisSetError(c,REDIS_ERR_IO,
+ sdscatprintf(sdsempty(), "setsockopt(SO_SNDTIMEO): %s", strerror(errno)));
+ return REDIS_ERR;
+ }
+ return REDIS_OK;
+}
+
int redisContextConnectTcp(redisContext *c, const char *addr, int port) {
int s;
int blocking = (c->flags & REDIS_BLOCK);