| Index: runtime/bin/socket_linux.cc
|
| diff --git a/runtime/bin/socket_linux.cc b/runtime/bin/socket_linux.cc
|
| index b9431e17ee64e1f3369f1b2f8523cd2061c8808a..203be0a64ab891b81eab922b39b0b8b4b4e08179 100644
|
| --- a/runtime/bin/socket_linux.cc
|
| +++ b/runtime/bin/socket_linux.cc
|
| @@ -307,11 +307,15 @@ AddressList<InterfaceSocketAddress>* Socket::ListInterfaces(
|
| return addresses;
|
| }
|
|
|
| +#ifndef SO_REUSEPORT
|
| +#define SO_REUSEPORT 15
|
| +#endif // SO_REUSEPORT
|
|
|
| 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,6 +324,28 @@ intptr_t ServerSocket::CreateBindListen(RawAddr addr,
|
| FDUtils::SetCloseOnExec(fd);
|
|
|
| int optval = 1;
|
| +
|
| + 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;
|
| TEMP_FAILURE_RETRY(
|
| setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval)));
|
|
|
|
|