diff options
author | Sangmoon Yi <jman@krafton.com> | 2019-08-12 10:54:12 +0900 |
---|---|---|
committer | Sangmoon Yi <jman@krafton.com> | 2019-08-12 10:54:12 +0900 |
commit | ab1762cd92845a75663c9046a6c039cd9757eb39 (patch) | |
tree | 205a8ed6b4864604e04f7d8ec992c500dfcdd29b | |
parent | f5f855c91239706b173e2412cea301f4a3643e2d (diff) |
fix timeout code in windows
-rw-r--r-- | net.c | 11 |
1 files changed, 9 insertions, 2 deletions
@@ -310,11 +310,18 @@ int redisCheckSocketError(redisContext *c) { } int redisContextSetTimeout(redisContext *c, const struct timeval tv) { - if (setsockopt(c->fd,SOL_SOCKET,SO_RCVTIMEO,&tv,sizeof(tv)) == -1) { + const void *to_ptr = &tv; + size_t to_sz = sizeof(tv); +#ifdef _WIN32 + DWORD timeout_msec = tv.tv_sec * 1000 + tv.tv_usec / 1000; + to_ptr = &timeout_msec; + to_sz = sizeof(timeout_msec); +#endif + if (setsockopt(c->fd,SOL_SOCKET,SO_RCVTIMEO,to_ptr,to_sz) == -1) { __redisSetErrorFromErrno(c,REDIS_ERR_IO,"setsockopt(SO_RCVTIMEO)"); return REDIS_ERR; } - if (setsockopt(c->fd,SOL_SOCKET,SO_SNDTIMEO,&tv,sizeof(tv)) == -1) { + if (setsockopt(c->fd,SOL_SOCKET,SO_SNDTIMEO,to_ptr,to_sz) == -1) { __redisSetErrorFromErrno(c,REDIS_ERR_IO,"setsockopt(SO_SNDTIMEO)"); return REDIS_ERR; } |