Make redisEnableKeepAlive a no-op on AF_UNIX connections. (#1215)
Fixes #1185
This commit is contained in:
parent
039385bd8b
commit
869f3d0ef1
1
.gitignore
vendored
1
.gitignore
vendored
@ -7,3 +7,4 @@
|
|||||||
/*.pc
|
/*.pc
|
||||||
*.dSYM
|
*.dSYM
|
||||||
tags
|
tags
|
||||||
|
compile_commands.json
|
||||||
|
|||||||
4
net.c
4
net.c
@ -173,6 +173,10 @@ int redisKeepAlive(redisContext *c, int interval) {
|
|||||||
int val = 1;
|
int val = 1;
|
||||||
redisFD fd = c->fd;
|
redisFD fd = c->fd;
|
||||||
|
|
||||||
|
/* TCP_KEEPALIVE makes no sense with AF_UNIX connections */
|
||||||
|
if (c->connection_type == REDIS_CONN_UNIX)
|
||||||
|
return REDIS_ERR;
|
||||||
|
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
if (setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &val, sizeof(val)) == -1){
|
if (setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &val, sizeof(val)) == -1){
|
||||||
__redisSetError(c,REDIS_ERR_OTHER,strerror(errno));
|
__redisSetError(c,REDIS_ERR_OTHER,strerror(errno));
|
||||||
|
|||||||
19
test.c
19
test.c
@ -431,6 +431,24 @@ static void test_tcp_options(struct config cfg) {
|
|||||||
redisFree(c);
|
redisFree(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void test_unix_keepalive(struct config cfg) {
|
||||||
|
redisContext *c;
|
||||||
|
redisReply *r;
|
||||||
|
|
||||||
|
c = do_connect(cfg);
|
||||||
|
|
||||||
|
test("Setting TCP_KEEPALIVE on a unix socket returns an error: ");
|
||||||
|
test_cond(redisEnableKeepAlive(c) == REDIS_ERR && c->err == 0);
|
||||||
|
|
||||||
|
test("Setting TCP_KEEPALIVE on a unix socket doesn't break the connection: ");
|
||||||
|
r = redisCommand(c, "PING");
|
||||||
|
test_cond(r != NULL && r->type == REDIS_REPLY_STATUS && r->len == 4 &&
|
||||||
|
!memcmp(r->str, "PONG", 4));
|
||||||
|
freeReplyObject(r);
|
||||||
|
|
||||||
|
redisFree(c);
|
||||||
|
}
|
||||||
|
|
||||||
static void test_reply_reader(void) {
|
static void test_reply_reader(void) {
|
||||||
redisReader *reader;
|
redisReader *reader;
|
||||||
void *reply, *root;
|
void *reply, *root;
|
||||||
@ -2363,6 +2381,7 @@ int main(int argc, char **argv) {
|
|||||||
test_blocking_connection_timeouts(cfg);
|
test_blocking_connection_timeouts(cfg);
|
||||||
test_blocking_io_errors(cfg);
|
test_blocking_io_errors(cfg);
|
||||||
test_invalid_timeout_errors(cfg);
|
test_invalid_timeout_errors(cfg);
|
||||||
|
test_unix_keepalive(cfg);
|
||||||
if (throughput) test_throughput(cfg);
|
if (throughput) test_throughput(cfg);
|
||||||
} else {
|
} else {
|
||||||
test_skipped();
|
test_skipped();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user