Index: runtime/bin/socket_macos.cc |
diff --git a/runtime/bin/socket_macos.cc b/runtime/bin/socket_macos.cc |
index be7beca2f90d80eb73b085164362091457285c8d..d7ee815c42f9f381effc4d3077d75908473a041a 100644 |
--- a/runtime/bin/socket_macos.cc |
+++ b/runtime/bin/socket_macos.cc |
@@ -311,7 +311,8 @@ AddressList<InterfaceSocketAddress>* Socket::ListInterfaces( |
intptr_t ServerSocket::CreateBindListen(RawAddr addr, |
intptr_t port, |
intptr_t backlog, |
- bool v6_only) { |
+ bool v6_only, |
+ bool reuse_port) { |
intptr_t fd; |
fd = TEMP_FAILURE_RETRY(socket(addr.ss.ss_family, SOCK_STREAM, 0)); |
@@ -320,8 +321,30 @@ intptr_t ServerSocket::CreateBindListen(RawAddr addr, |
FDUtils::SetCloseOnExec(fd); |
int optval = 1; |
- VOID_TEMP_FAILURE_RETRY( |
- setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval))); |
+ |
+ if (reuse_port) { |
+ if (TEMP_FAILURE_RETRY(setsockopt(fd, |
+ SOL_SOCKET, |
+ SO_REUSEPORT, |
+ &optval, |
+ sizeof(optval))) != 0) { |
+ int e = errno; |
+ VOID_TEMP_FAILURE_RETRY(close(fd)); |
+ errno = e; |
+ return -1; |
+ } |
+ } else { |
+ optval = 0; |
+ VOID_TEMP_FAILURE_RETRY(setsockopt(fd, |
+ SOL_SOCKET, |
+ SO_REUSEPORT, |
+ &optval, |
+ sizeof(optval))); |
+ |
+ optval = 1; |
+ VOID_TEMP_FAILURE_RETRY( |
+ setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval))); |
+ } |
if (addr.ss.ss_family == AF_INET6) { |
optval = v6_only ? 1 : 0; |