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
63ce20dd
Commit
63ce20dd
authored
Apr 10, 2013
by
Pieter Noordhuis
Browse files
Merge pull request #156 from abedra/master
Set error on invalid timval values for redisConnectWithTimeout (Fixes #154)
parents
6bd11724
fca66b9e
Changes
2
Hide whitespace changes
Inline
Side-by-side
net.c
View file @
63ce20dd
...
...
@@ -136,6 +136,7 @@ static int redisContextWaitReady(redisContext *c, int fd, const struct timeval *
/* Only use timeout when not NULL. */
if
(
timeout
!=
NULL
)
{
if
(
timeout
->
tv_usec
>
1000000
||
timeout
->
tv_sec
>
__MAX_MSEC
)
{
__redisSetErrorFromErrno
(
c
,
REDIS_ERR_IO
,
NULL
);
close
(
fd
);
return
REDIS_ERR
;
}
...
...
test.c
View file @
63ce20dd
...
...
@@ -8,6 +8,7 @@
#include <unistd.h>
#include <signal.h>
#include <errno.h>
#include <limits.h>
#include "hiredis.h"
...
...
@@ -22,6 +23,7 @@ struct config {
struct
{
const
char
*
host
;
int
port
;
struct
timeval
timeout
;
}
tcp
;
struct
{
...
...
@@ -433,6 +435,30 @@ static void test_blocking_io_errors(struct config config) {
redisFree
(
c
);
}
static
void
test_invalid_timeout_errors
(
struct
config
config
)
{
redisContext
*
c
;
test
(
"Set error when an invalid timeout usec value is given to redisConnectWithTimeout: "
);
config
.
tcp
.
timeout
.
tv_sec
=
0
;
config
.
tcp
.
timeout
.
tv_usec
=
10000001
;
c
=
redisConnectWithTimeout
(
config
.
tcp
.
host
,
config
.
tcp
.
port
,
config
.
tcp
.
timeout
);
test_cond
(
c
->
err
==
REDIS_ERR_IO
);
test
(
"Set error when an invalid timeout sec value is given to redisConnectWithTimeout: "
);
config
.
tcp
.
timeout
.
tv_sec
=
(((
LONG_MAX
)
-
999
)
/
1000
)
+
1
;
config
.
tcp
.
timeout
.
tv_usec
=
0
;
c
=
redisConnectWithTimeout
(
config
.
tcp
.
host
,
config
.
tcp
.
port
,
config
.
tcp
.
timeout
);
test_cond
(
c
->
err
==
REDIS_ERR_IO
);
redisFree
(
c
);
}
static
void
test_throughput
(
struct
config
config
)
{
redisContext
*
c
=
connect
(
config
);
redisReply
**
replies
;
...
...
@@ -641,6 +667,7 @@ int main(int argc, char **argv) {
cfg
.
type
=
CONN_TCP
;
test_blocking_connection
(
cfg
);
test_blocking_io_errors
(
cfg
);
test_invalid_timeout_errors
(
cfg
);
if
(
throughput
)
test_throughput
(
cfg
);
printf
(
"
\n
Testing against Unix socket connection (%s):
\n
"
,
cfg
.
unix
.
path
);
...
...
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