| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "platform/globals.h" | 5 #include "platform/globals.h" |
| 6 #if defined(TARGET_OS_MACOS) | 6 #if defined(TARGET_OS_MACOS) |
| 7 | 7 |
| 8 #include <errno.h> // NOLINT | 8 #include <errno.h> // NOLINT |
| 9 #include <stdio.h> // NOLINT | 9 #include <stdio.h> // NOLINT |
| 10 #include <stdlib.h> // NOLINT | 10 #include <stdlib.h> // NOLINT |
| (...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 } | 304 } |
| 305 } | 305 } |
| 306 freeifaddrs(ifaddr); | 306 freeifaddrs(ifaddr); |
| 307 return addresses; | 307 return addresses; |
| 308 } | 308 } |
| 309 | 309 |
| 310 | 310 |
| 311 intptr_t ServerSocket::CreateBindListen(RawAddr addr, | 311 intptr_t ServerSocket::CreateBindListen(RawAddr addr, |
| 312 intptr_t port, | 312 intptr_t port, |
| 313 intptr_t backlog, | 313 intptr_t backlog, |
| 314 bool v6_only) { | 314 bool v6_only, |
| 315 bool reuse_port) { |
| 315 intptr_t fd; | 316 intptr_t fd; |
| 316 | 317 |
| 317 fd = TEMP_FAILURE_RETRY(socket(addr.ss.ss_family, SOCK_STREAM, 0)); | 318 fd = TEMP_FAILURE_RETRY(socket(addr.ss.ss_family, SOCK_STREAM, 0)); |
| 318 if (fd < 0) return -1; | 319 if (fd < 0) return -1; |
| 319 | 320 |
| 320 FDUtils::SetCloseOnExec(fd); | 321 FDUtils::SetCloseOnExec(fd); |
| 321 | 322 |
| 322 int optval = 1; | 323 int optval = 1; |
| 323 VOID_TEMP_FAILURE_RETRY( | 324 |
| 324 setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval))); | 325 if (reuse_port) { |
| 326 if (TEMP_FAILURE_RETRY(setsockopt(fd, |
| 327 SOL_SOCKET, |
| 328 SO_REUSEPORT, |
| 329 &optval, |
| 330 sizeof(optval))) != 0) { |
| 331 int e = errno; |
| 332 VOID_TEMP_FAILURE_RETRY(close(fd)); |
| 333 errno = e; |
| 334 return -1; |
| 335 } |
| 336 } else { |
| 337 optval = 0; |
| 338 VOID_TEMP_FAILURE_RETRY(setsockopt(fd, |
| 339 SOL_SOCKET, |
| 340 SO_REUSEPORT, |
| 341 &optval, |
| 342 sizeof(optval))); |
| 343 |
| 344 optval = 1; |
| 345 VOID_TEMP_FAILURE_RETRY( |
| 346 setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval))); |
| 347 } |
| 325 | 348 |
| 326 if (addr.ss.ss_family == AF_INET6) { | 349 if (addr.ss.ss_family == AF_INET6) { |
| 327 optval = v6_only ? 1 : 0; | 350 optval = v6_only ? 1 : 0; |
| 328 VOID_TEMP_FAILURE_RETRY( | 351 VOID_TEMP_FAILURE_RETRY( |
| 329 setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, &optval, sizeof(optval))); | 352 setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, &optval, sizeof(optval))); |
| 330 } | 353 } |
| 331 | 354 |
| 332 SocketAddress::SetAddrPort(&addr, port); | 355 SocketAddress::SetAddrPort(&addr, port); |
| 333 if (TEMP_FAILURE_RETRY( | 356 if (TEMP_FAILURE_RETRY( |
| 334 bind(fd, | 357 bind(fd, |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 407 IPPROTO_TCP, | 430 IPPROTO_TCP, |
| 408 TCP_NODELAY, | 431 TCP_NODELAY, |
| 409 reinterpret_cast<char *>(&on), | 432 reinterpret_cast<char *>(&on), |
| 410 sizeof(on))) == 0; | 433 sizeof(on))) == 0; |
| 411 } | 434 } |
| 412 | 435 |
| 413 } // namespace bin | 436 } // namespace bin |
| 414 } // namespace dart | 437 } // namespace dart |
| 415 | 438 |
| 416 #endif // defined(TARGET_OS_MACOS) | 439 #endif // defined(TARGET_OS_MACOS) |
| OLD | NEW |