Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(330)

Unified Diff: runtime/bin/socket_macos.cc

Issue 25511002: Add reusePort argument to ServerSocket. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Mac os X version. Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/bin/socket_linux.cc ('k') | runtime/bin/socket_patch.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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;
« no previous file with comments | « runtime/bin/socket_linux.cc ('k') | runtime/bin/socket_patch.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698