Do store command timeout in the context for redisSetTimeout (#593)
parent
c57cad658d
commit
75cb6c1ea6
6
net.c
6
net.c
|
@ -50,6 +50,8 @@
|
||||||
/* Defined in hiredis.c */
|
/* Defined in hiredis.c */
|
||||||
void __redisSetError(redisContext *c, int type, const char *str);
|
void __redisSetError(redisContext *c, int type, const char *str);
|
||||||
|
|
||||||
|
int redisContextUpdateCommandTimeout(redisContext *c, const struct timeval *timeout);
|
||||||
|
|
||||||
void redisNetClose(redisContext *c) {
|
void redisNetClose(redisContext *c) {
|
||||||
if (c && c->fd != REDIS_INVALID_FD) {
|
if (c && c->fd != REDIS_INVALID_FD) {
|
||||||
close(c->fd);
|
close(c->fd);
|
||||||
|
@ -333,6 +335,10 @@ int redisContextSetTimeout(redisContext *c, const struct timeval tv) {
|
||||||
const void *to_ptr = &tv;
|
const void *to_ptr = &tv;
|
||||||
size_t to_sz = sizeof(tv);
|
size_t to_sz = sizeof(tv);
|
||||||
|
|
||||||
|
if (redisContextUpdateCommandTimeout(c, &tv) != REDIS_OK) {
|
||||||
|
__redisSetError(c, REDIS_ERR_OOM, "Out of memory");
|
||||||
|
return REDIS_ERR;
|
||||||
|
}
|
||||||
if (setsockopt(c->fd,SOL_SOCKET,SO_RCVTIMEO,to_ptr,to_sz) == -1) {
|
if (setsockopt(c->fd,SOL_SOCKET,SO_RCVTIMEO,to_ptr,to_sz) == -1) {
|
||||||
__redisSetErrorFromErrno(c,REDIS_ERR_IO,"setsockopt(SO_RCVTIMEO)");
|
__redisSetErrorFromErrno(c,REDIS_ERR_IO,"setsockopt(SO_RCVTIMEO)");
|
||||||
return REDIS_ERR;
|
return REDIS_ERR;
|
||||||
|
|
9
test.c
9
test.c
|
@ -1156,7 +1156,13 @@ static void test_blocking_connection_timeouts(struct config config) {
|
||||||
test("Does not return a reply when the command times out: ");
|
test("Does not return a reply when the command times out: ");
|
||||||
if (detect_debug_sleep(c)) {
|
if (detect_debug_sleep(c)) {
|
||||||
redisAppendFormattedCommand(c, sleep_cmd, strlen(sleep_cmd));
|
redisAppendFormattedCommand(c, sleep_cmd, strlen(sleep_cmd));
|
||||||
|
|
||||||
|
// flush connection buffer without waiting for the reply
|
||||||
s = c->funcs->write(c);
|
s = c->funcs->write(c);
|
||||||
|
assert(s == (ssize_t)sdslen(c->obuf));
|
||||||
|
sdsfree(c->obuf);
|
||||||
|
c->obuf = sdsempty();
|
||||||
|
|
||||||
tv.tv_sec = 0;
|
tv.tv_sec = 0;
|
||||||
tv.tv_usec = 10000;
|
tv.tv_usec = 10000;
|
||||||
redisSetTimeout(c, tv);
|
redisSetTimeout(c, tv);
|
||||||
|
@ -1169,6 +1175,9 @@ static void test_blocking_connection_timeouts(struct config config) {
|
||||||
strcmp(c->errstr, "recv timeout") == 0);
|
strcmp(c->errstr, "recv timeout") == 0);
|
||||||
#endif
|
#endif
|
||||||
freeReplyObject(reply);
|
freeReplyObject(reply);
|
||||||
|
|
||||||
|
// wait for the DEBUG SLEEP to complete so that Redis server is unblocked for the following tests
|
||||||
|
sleep(3);
|
||||||
} else {
|
} else {
|
||||||
test_skipped();
|
test_skipped();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue