Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
hiredis
Commits
9c7c694c
Unverified
Commit
9c7c694c
authored
Aug 13, 2019
by
Mark Nunberg
Committed by
GitHub
Aug 13, 2019
Browse files
Merge pull request #670 from jman-krafton/master
fix timeout code in windows
parents
ac49287c
8e61d573
Changes
1
Hide whitespace changes
Inline
Side-by-side
net.c
View file @
9c7c694c
...
...
@@ -63,6 +63,10 @@ int redisNetRead(redisContext *c, char *buf, size_t bufcap) {
if
((
errno
==
EWOULDBLOCK
&&
!
(
c
->
flags
&
REDIS_BLOCK
))
||
(
errno
==
EINTR
))
{
/* Try again later */
return
0
;
}
else
if
(
errno
==
ETIMEDOUT
&&
(
c
->
flags
&
REDIS_BLOCK
))
{
/* especially in windows */
__redisSetError
(
c
,
REDIS_ERR_TIMEOUT
,
"recv timeout"
);
return
-
1
;
}
else
{
__redisSetError
(
c
,
REDIS_ERR_IO
,
NULL
);
return
-
1
;
...
...
@@ -310,11 +314,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
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment