| 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_WINDOWS) | 6 #if defined(TARGET_OS_WINDOWS) |
| 7 | 7 |
| 8 #include "bin/builtin.h" | 8 #include "bin/builtin.h" |
| 9 #include "bin/eventhandler.h" | 9 #include "bin/eventhandler.h" |
| 10 #include "bin/file.h" | 10 #include "bin/file.h" |
| (...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 330 } | 330 } |
| 331 } | 331 } |
| 332 free(addrs); | 332 free(addrs); |
| 333 return addresses; | 333 return addresses; |
| 334 } | 334 } |
| 335 | 335 |
| 336 | 336 |
| 337 intptr_t ServerSocket::CreateBindListen(RawAddr addr, | 337 intptr_t ServerSocket::CreateBindListen(RawAddr addr, |
| 338 intptr_t port, | 338 intptr_t port, |
| 339 intptr_t backlog, | 339 intptr_t backlog, |
| 340 bool v6_only) { | 340 bool v6_only, |
| 341 bool reuse_port) { |
| 341 SOCKET s = socket(addr.ss.ss_family, SOCK_STREAM, IPPROTO_TCP); | 342 SOCKET s = socket(addr.ss.ss_family, SOCK_STREAM, IPPROTO_TCP); |
| 342 if (s == INVALID_SOCKET) { | 343 if (s == INVALID_SOCKET) { |
| 343 return -1; | 344 return -1; |
| 344 } | 345 } |
| 345 | 346 |
| 346 BOOL optval = true; | 347 BOOL optval = true; |
| 347 int status = setsockopt(s, | 348 int status; |
| 348 SOL_SOCKET, | 349 if (reuse_port) { |
| 349 SO_EXCLUSIVEADDRUSE, | 350 status = setsockopt(s, |
| 350 reinterpret_cast<const char*>(&optval), | 351 SOL_SOCKET, |
| 351 sizeof(optval)); | 352 SO_REUSEADDR, |
| 353 reinterpret_cast<const char*>(&optval), |
| 354 sizeof(optval)); |
| 355 } else { |
| 356 status = setsockopt(s, |
| 357 SOL_SOCKET, |
| 358 SO_EXCLUSIVEADDRUSE, |
| 359 reinterpret_cast<const char*>(&optval), |
| 360 sizeof(optval)); |
| 361 } |
| 352 if (status == SOCKET_ERROR) { | 362 if (status == SOCKET_ERROR) { |
| 353 DWORD rc = WSAGetLastError(); | 363 DWORD rc = WSAGetLastError(); |
| 354 closesocket(s); | 364 closesocket(s); |
| 355 SetLastError(rc); | 365 SetLastError(rc); |
| 356 return -1; | 366 return -1; |
| 357 } | 367 } |
| 358 | 368 |
| 359 if (addr.ss.ss_family == AF_INET6) { | 369 if (addr.ss.ss_family == AF_INET6) { |
| 360 optval = v6_only; | 370 optval = v6_only; |
| 361 setsockopt(s, | 371 setsockopt(s, |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 439 IPPROTO_TCP, | 449 IPPROTO_TCP, |
| 440 TCP_NODELAY, | 450 TCP_NODELAY, |
| 441 reinterpret_cast<char *>(&on), | 451 reinterpret_cast<char *>(&on), |
| 442 sizeof(on)) == 0; | 452 sizeof(on)) == 0; |
| 443 } | 453 } |
| 444 | 454 |
| 445 } // namespace bin | 455 } // namespace bin |
| 446 } // namespace dart | 456 } // namespace dart |
| 447 | 457 |
| 448 #endif // defined(TARGET_OS_WINDOWS) | 458 #endif // defined(TARGET_OS_WINDOWS) |
| OLD | NEW |