summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAllan <kaoshi.juan@163.com>2013-07-25 15:28:33 +0800
committerantirez <antirez@gmail.com>2013-08-21 11:41:25 +0200
commit6c2b34a4656f432c8199c2bba454b64ec1438fd4 (patch)
tree0db1b3023210d06367704964d3792bf1d4ff4260
parent0a4656d63f90fa6bd2f3bbb488eaaaf752ed1d83 (diff)
downloadredis-6c2b34a4656f432c8199c2bba454b64ec1438fd4.tar.gz
fixed initServer failed if no IPV4 or no IPV6
-rw-r--r--src/redis.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/src/redis.c b/src/redis.c
index bdfe607a3..d591468c1 100644
--- a/src/redis.c
+++ b/src/redis.c
@@ -1436,6 +1436,7 @@ void adjustOpenFilesLimit(void) {
void initServer() {
int j;
+ int ip_count;
signal(SIGHUP, SIG_IGN);
signal(SIGPIPE, SIG_IGN);
@@ -1467,12 +1468,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. */