mirror of
https://github.com/fluencelabs/redis
synced 2025-03-25 11:51:03 +00:00
fix tcp binding when IPv6 is unsupported
This commit is contained in:
parent
d35deb2327
commit
92038286e8
@ -486,7 +486,7 @@ static int _anetTcpServer(char *err, int port, char *bindaddr, int af, int backl
|
|||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
if (p == NULL) {
|
if (p == NULL) {
|
||||||
anetSetError(err, "unable to bind socket");
|
anetSetError(err, "unable to bind socket, errno: %d", errno);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
22
src/server.c
22
src/server.c
@ -1636,6 +1636,7 @@ int listenToPort(int port, int *fds, int *count) {
|
|||||||
if (server.bindaddr_count == 0) server.bindaddr[0] = NULL;
|
if (server.bindaddr_count == 0) server.bindaddr[0] = NULL;
|
||||||
for (j = 0; j < server.bindaddr_count || j == 0; j++) {
|
for (j = 0; j < server.bindaddr_count || j == 0; j++) {
|
||||||
if (server.bindaddr[j] == NULL) {
|
if (server.bindaddr[j] == NULL) {
|
||||||
|
int unsupported = 0;
|
||||||
/* Bind * for both IPv6 and IPv4, we enter here only if
|
/* Bind * for both IPv6 and IPv4, we enter here only if
|
||||||
* server.bindaddr_count == 0. */
|
* server.bindaddr_count == 0. */
|
||||||
fds[*count] = anetTcp6Server(server.neterr,port,NULL,
|
fds[*count] = anetTcp6Server(server.neterr,port,NULL,
|
||||||
@ -1643,19 +1644,22 @@ int listenToPort(int port, int *fds, int *count) {
|
|||||||
if (fds[*count] != ANET_ERR) {
|
if (fds[*count] != ANET_ERR) {
|
||||||
anetNonBlock(NULL,fds[*count]);
|
anetNonBlock(NULL,fds[*count]);
|
||||||
(*count)++;
|
(*count)++;
|
||||||
|
} else if (errno == EAFNOSUPPORT)
|
||||||
|
unsupported++;
|
||||||
|
|
||||||
/* Bind the IPv4 address as well. */
|
/* Bind the IPv4 address as well. */
|
||||||
fds[*count] = anetTcpServer(server.neterr,port,NULL,
|
fds[*count] = anetTcpServer(server.neterr,port,NULL,
|
||||||
server.tcp_backlog);
|
server.tcp_backlog);
|
||||||
if (fds[*count] != ANET_ERR) {
|
if (fds[*count] != ANET_ERR) {
|
||||||
anetNonBlock(NULL,fds[*count]);
|
anetNonBlock(NULL,fds[*count]);
|
||||||
(*count)++;
|
(*count)++;
|
||||||
}
|
} else if (errno == EAFNOSUPPORT)
|
||||||
}
|
unsupported++;
|
||||||
/* Exit the loop if we were able to bind * on IPv4 and IPv6,
|
/* Exit the loop if we were able to bind * on IPv4 and IPv6,
|
||||||
|
* or if one is unsupported by th OS.
|
||||||
* otherwise fds[*count] will be ANET_ERR and we'll print an
|
* otherwise fds[*count] will be ANET_ERR and we'll print an
|
||||||
* error and return to the caller with an error. */
|
* error and return to the caller with an error. */
|
||||||
if (*count == 2) break;
|
if (*count + unsupported == 2) break;
|
||||||
} else if (strchr(server.bindaddr[j],':')) {
|
} else if (strchr(server.bindaddr[j],':')) {
|
||||||
/* Bind IPv6 address. */
|
/* Bind IPv6 address. */
|
||||||
fds[*count] = anetTcp6Server(server.neterr,port,server.bindaddr[j],
|
fds[*count] = anetTcp6Server(server.neterr,port,server.bindaddr[j],
|
||||||
|
Loading…
x
Reference in New Issue
Block a user