Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ruanhaishen
hiredis
Commits
62c8054d
Commit
62c8054d
authored
Sep 19, 2010
by
Pieter Noordhuis
Browse files
Clean up when there is an I/O error
parent
457cdbf7
Changes
2
Hide whitespace changes
Inline
Side-by-side
hiredis.c
View file @
62c8054d
...
...
@@ -73,7 +73,7 @@ redisReply *redisConnect(int *fd, const char *ip, int port) {
/* Create a reply object */
static
redisReply
*
createReplyObject
(
int
type
,
sds
reply
)
{
redisReply
*
r
=
m
alloc
(
sizeof
(
*
r
));
redisReply
*
r
=
c
alloc
(
sizeof
(
*
r
)
,
1
);
if
(
!
r
)
redisOOM
();
r
->
type
=
type
;
...
...
@@ -94,7 +94,8 @@ void freeReplyObject(redisReply *r) {
free
(
r
->
element
);
break
;
default:
sdsfree
(
r
->
reply
);
if
(
r
->
reply
!=
NULL
)
sdsfree
(
r
->
reply
);
break
;
}
free
(
r
);
...
...
@@ -303,8 +304,13 @@ static redisReply *redisReadReply(int fd) {
}
/* read from socket into buffer */
if
((
bytes
=
read
(
fd
,
r
.
buf
+
r
.
avail
,
READ_BUFFER_SIZE
))
<=
0
)
if
((
bytes
=
read
(
fd
,
r
.
buf
+
r
.
avail
,
READ_BUFFER_SIZE
))
<=
0
)
{
/* rlist[0] is the "root" reply object */
freeReplyObject
(
r
.
rlist
[
0
]);
free
(
r
.
buf
);
free
(
r
.
rlist
);
return
redisIOError
();
}
r
.
avail
+=
bytes
;
r
.
buf
[
r
.
avail
]
=
'\0'
;
...
...
test.c
View file @
62c8054d
...
...
@@ -15,20 +15,31 @@ long long usec(void) {
return
(((
long
long
)
tv
.
tv_sec
)
*
1000000
)
+
tv
.
tv_usec
;
}
void
connect
(
int
*
fd
)
{
redisReply
*
reply
=
redisConnect
(
fd
,
"127.0.0.1"
,
6379
);
if
(
reply
!=
NULL
)
{
printf
(
"Connection error: %s"
,
reply
->
reply
);
exit
(
1
);
}
}
int
main
(
void
)
{
int
fd
;
int
i
,
fails
=
0
;
long
long
t1
,
t2
;
redisReply
*
reply
;
connect
(
&
fd
);
reply
=
redisConnect
(
&
fd
,
"127.0.0.1"
,
6379
);
if
(
reply
!=
NULL
)
{
printf
(
"Connection error: %s"
,
reply
->
reply
);
exit
(
1
);
}
/* test 0 */
printf
(
"#0 Returns I/O error when the connection is lost: "
);
reply
=
redisCommand
(
fd
,
"QUIT"
);
test_cond
(
reply
->
type
==
REDIS_REPLY_ERROR
&&
strcasecmp
(
reply
->
reply
,
"i/o error"
)
==
0
);
freeReplyObject
(
reply
);
connect
(
&
fd
);
/* reconnect */
/* test 1 */
printf
(
"
\n
#1 Is able to deliver commands: "
);
printf
(
"#1 Is able to deliver commands: "
);
reply
=
redisCommand
(
fd
,
"PING"
);
test_cond
(
reply
->
type
==
REDIS_REPLY_STRING
&&
strcasecmp
(
reply
->
reply
,
"pong"
)
==
0
)
...
...
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