diff options
author | antirez <antirez@gmail.com> | 2016-05-05 10:02:42 +0200 |
---|---|---|
committer | antirez <antirez@gmail.com> | 2016-05-05 10:02:42 +0200 |
commit | c77b95fd01cb6959005121b91e21037cd3da1c88 (patch) | |
tree | 56a5cd16d115ba6867b1aa5376b4d004386420e1 /src | |
parent | 0bb787d3ad49977ed92dfe711f54494ed0abccdf (diff) | |
download | redis-c77b95fd01cb6959005121b91e21037cd3da1c88.tar.gz |
Bind both IPv4 and IPv6 or exit with an error by default.
Thanks to @tushar2708 for the PR. I applied a slightly different fix.
Thanks to @cespare for reporting.
Close #3024
Close #3020
Diffstat (limited to 'src')
-rw-r--r-- | src/server.c | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/src/server.c b/src/server.c index bab8bb67e..bd56ceeb3 100644 --- a/src/server.c +++ b/src/server.c @@ -1789,17 +1789,19 @@ int listenToPort(int port, int *fds, int *count) { if (fds[*count] != ANET_ERR) { anetNonBlock(NULL,fds[*count]); (*count)++; + + /* Bind the IPv4 address as well. */ + fds[*count] = anetTcpServer(server.neterr,port,NULL, + server.tcp_backlog); + if (fds[*count] != ANET_ERR) { + anetNonBlock(NULL,fds[*count]); + (*count)++; + } } - fds[*count] = anetTcpServer(server.neterr,port,NULL, - server.tcp_backlog); - if (fds[*count] != ANET_ERR) { - anetNonBlock(NULL,fds[*count]); - (*count)++; - } - /* Exit the loop if we were able to bind * on IPv4 or IPv6, + /* Exit the loop if we were able to bind * on IPv4 and IPv6, * otherwise fds[*count] will be ANET_ERR and we'll print an * error and return to the caller with an error. */ - if (*count) break; + if (*count == 2) break; } else if (strchr(server.bindaddr[j],':')) { /* Bind IPv6 address. */ fds[*count] = anetTcp6Server(server.neterr,port,server.bindaddr[j], |