@@ -63,6 +63,10 @@ int redisNetRead(redisContext *c, char *buf, size_t bufcap) {
63
63
if ((errno == EWOULDBLOCK && !(c -> flags & REDIS_BLOCK )) || (errno == EINTR )) {
64
64
/* Try again later */
65
65
return 0 ;
66
+ } else if (errno == ETIMEDOUT && (c -> flags & REDIS_BLOCK )) {
67
+ /* especially in windows */
68
+ __redisSetError (c , REDIS_ERR_TIMEOUT , "recv timeout" );
69
+ return -1 ;
66
70
} else {
67
71
__redisSetError (c , REDIS_ERR_IO , NULL );
68
72
return -1 ;
@@ -310,11 +314,18 @@ int redisCheckSocketError(redisContext *c) {
310
314
}
311
315
312
316
int redisContextSetTimeout (redisContext * c , const struct timeval tv ) {
313
- if (setsockopt (c -> fd ,SOL_SOCKET ,SO_RCVTIMEO ,& tv ,sizeof (tv )) == -1 ) {
317
+ const void * to_ptr = & tv ;
318
+ size_t to_sz = sizeof (tv );
319
+ #ifdef _WIN32
320
+ DWORD timeout_msec = tv .tv_sec * 1000 + tv .tv_usec / 1000 ;
321
+ to_ptr = & timeout_msec ;
322
+ to_sz = sizeof (timeout_msec );
323
+ #endif
324
+ if (setsockopt (c -> fd ,SOL_SOCKET ,SO_RCVTIMEO ,to_ptr ,to_sz ) == -1 ) {
314
325
__redisSetErrorFromErrno (c ,REDIS_ERR_IO ,"setsockopt(SO_RCVTIMEO)" );
315
326
return REDIS_ERR ;
316
327
}
317
- if (setsockopt (c -> fd ,SOL_SOCKET ,SO_SNDTIMEO ,& tv , sizeof ( tv ) ) == -1 ) {
328
+ if (setsockopt (c -> fd ,SOL_SOCKET ,SO_SNDTIMEO ,to_ptr , to_sz ) == -1 ) {
318
329
__redisSetErrorFromErrno (c ,REDIS_ERR_IO ,"setsockopt(SO_SNDTIMEO)" );
319
330
return REDIS_ERR ;
320
331
}
0 commit comments