Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
92038286
Commit
92038286
authored
Aug 21, 2016
by
oranagra
Committed by
antirez
Sep 09, 2016
Browse files
fix tcp binding when IPv6 is unsupported
parent
d35deb23
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/anet.c
View file @
92038286
...
@@ -486,7 +486,7 @@ static int _anetTcpServer(char *err, int port, char *bindaddr, int af, int backl
...
@@ -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
;
}
}
...
...
src/server.c
View file @
92038286
...
@@ -1636,6 +1636,7 @@ int listenToPort(int port, int *fds, int *count) {
...
@@ -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) {
...
@@ -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
],
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment