From cba7a4e69a9fbfadf0e0206a0a3859abf26ef0f8 Mon Sep 17 00:00:00 2001 From: Allan Date: Thu, 25 Jul 2013 15:28:33 +0800 Subject: [PATCH] fixed initServer failed if no IPV4 or no IPV6 --- src/redis.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/redis.c b/src/redis.c index 7e1c2fa5b..4e842fc62 100644 --- a/src/redis.c +++ b/src/redis.c @@ -1403,6 +1403,7 @@ void adjustOpenFilesLimit(void) { void initServer() { int j; + int ip_count; signal(SIGHUP, SIG_IGN); signal(SIGPIPE, SIG_IGN); @@ -1434,12 +1435,18 @@ void initServer() { if (server.bindaddr_count == 0) server.bindaddr[0] = NULL; for (j = 0; j < server.bindaddr_count || j == 0; j++) { if (server.bindaddr[j] == NULL) { - /* Bind * for both IPv6 and IPv4. */ - server.ipfd[server.ipfd_count] = anetTcp6Server(server.neterr,server.port,NULL); - if (server.ipfd[server.ipfd_count] != ANET_ERR) server.ipfd_count++; + /* Bind * for both IPv6 and IPv4. + * Should consider that someone only has IPV6 and someone only get IPV4 */ + ip_count = 0; + server.ipfd[ip_count] = anetTcp6Server(server.neterr,server.port,NULL); + if (server.ipfd[ip_count] != ANET_ERR) ip_count++; - server.ipfd[server.ipfd_count] = anetTcpServer(server.neterr,server.port,NULL); + server.ipfd[ip_count] = anetTcpServer(server.neterr,server.port,NULL); + if(server.ipfd[ip_count] != ANET_ERR ) ip_count++; + /* It should be ip_count plus one + * because out of this branch, the server.ipfd_count would increase */ + server.ipfd_count = ip_count - 1; } else if (strchr(server.bindaddr[j],':')) { /* Bind IPv6 address. */