summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2016-05-05 10:02:42 +0200
committerantirez <antirez@gmail.com>2016-05-05 10:02:42 +0200
commitc77b95fd01cb6959005121b91e21037cd3da1c88 (patch)
tree56a5cd16d115ba6867b1aa5376b4d004386420e1 /src
parent0bb787d3ad49977ed92dfe711f54494ed0abccdf (diff)
downloadredis-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.c18
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],