Skip to content

Commit ab1762c

Browse files
committed
fix timeout code in windows
1 parent f5f855c commit ab1762c

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

net.c

+9-2
Original file line numberDiff line numberDiff line change
@@ -310,11 +310,18 @@ int redisCheckSocketError(redisContext *c) {
310310
}
311311

312312
int redisContextSetTimeout(redisContext *c, const struct timeval tv) {
313-
if (setsockopt(c->fd,SOL_SOCKET,SO_RCVTIMEO,&tv,sizeof(tv)) == -1) {
313+
const void *to_ptr = &tv;
314+
size_t to_sz = sizeof(tv);
315+
#ifdef _WIN32
316+
DWORD timeout_msec = tv.tv_sec * 1000 + tv.tv_usec / 1000;
317+
to_ptr = &timeout_msec;
318+
to_sz = sizeof(timeout_msec);
319+
#endif
320+
if (setsockopt(c->fd,SOL_SOCKET,SO_RCVTIMEO,to_ptr,to_sz) == -1) {
314321
__redisSetErrorFromErrno(c,REDIS_ERR_IO,"setsockopt(SO_RCVTIMEO)");
315322
return REDIS_ERR;
316323
}
317-
if (setsockopt(c->fd,SOL_SOCKET,SO_SNDTIMEO,&tv,sizeof(tv)) == -1) {
324+
if (setsockopt(c->fd,SOL_SOCKET,SO_SNDTIMEO,to_ptr,to_sz) == -1) {
318325
__redisSetErrorFromErrno(c,REDIS_ERR_IO,"setsockopt(SO_SNDTIMEO)");
319326
return REDIS_ERR;
320327
}

0 commit comments

Comments
 (0)