| 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_LINUX) | 6 #if defined(TARGET_OS_LINUX) |
| 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 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 305 intptr_t fd; | 305 intptr_t fd; |
| 306 | 306 |
| 307 fd = TEMP_FAILURE_RETRY( | 307 fd = TEMP_FAILURE_RETRY( |
| 308 socket(addr->addr.sa_family, SOCK_DGRAM, IPPROTO_UDP)); | 308 socket(addr->addr.sa_family, SOCK_DGRAM, IPPROTO_UDP)); |
| 309 if (fd < 0) return -1; | 309 if (fd < 0) return -1; |
| 310 | 310 |
| 311 FDUtils::SetCloseOnExec(fd); | 311 FDUtils::SetCloseOnExec(fd); |
| 312 | 312 |
| 313 if (reuseAddress) { | 313 if (reuseAddress) { |
| 314 int optval = 1; | 314 int optval = 1; |
| 315 TEMP_FAILURE_RETRY( | 315 VOID_TEMP_FAILURE_RETRY( |
| 316 setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval))); | 316 setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval))); |
| 317 } | 317 } |
| 318 | 318 |
| 319 SocketAddress::SetAddrPort(addr, port); | 319 SocketAddress::SetAddrPort(addr, port); |
| 320 if (TEMP_FAILURE_RETRY( | 320 if (TEMP_FAILURE_RETRY( |
| 321 bind(fd, | 321 bind(fd, |
| 322 &addr->addr, | 322 &addr->addr, |
| 323 SocketAddress::GetAddrLength(addr))) < 0) { | 323 SocketAddress::GetAddrLength(addr))) < 0) { |
| 324 TEMP_FAILURE_RETRY(close(fd)); | 324 TEMP_FAILURE_RETRY(close(fd)); |
| 325 return -1; | 325 return -1; |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 400 optval = v6_only ? 1 : 0; | 400 optval = v6_only ? 1 : 0; |
| 401 TEMP_FAILURE_RETRY( | 401 TEMP_FAILURE_RETRY( |
| 402 setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, &optval, sizeof(optval))); | 402 setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, &optval, sizeof(optval))); |
| 403 } | 403 } |
| 404 | 404 |
| 405 SocketAddress::SetAddrPort(&addr, port); | 405 SocketAddress::SetAddrPort(&addr, port); |
| 406 if (TEMP_FAILURE_RETRY( | 406 if (TEMP_FAILURE_RETRY( |
| 407 bind(fd, | 407 bind(fd, |
| 408 &addr.addr, | 408 &addr.addr, |
| 409 SocketAddress::GetAddrLength(&addr))) < 0) { | 409 SocketAddress::GetAddrLength(&addr))) < 0) { |
| 410 TEMP_FAILURE_RETRY(close(fd)); | 410 VOID_TEMP_FAILURE_RETRY(close(fd)); |
| 411 return -1; | 411 return -1; |
| 412 } | 412 } |
| 413 | 413 |
| 414 // Test for invalid socket port 65535 (some browsers disallow it). | 414 // Test for invalid socket port 65535 (some browsers disallow it). |
| 415 if (port == 0 && Socket::GetPort(fd) == 65535) { | 415 if (port == 0 && Socket::GetPort(fd) == 65535) { |
| 416 // Don't close the socket until we have created a new socket, ensuring | 416 // Don't close the socket until we have created a new socket, ensuring |
| 417 // that we do not get the bad port number again. | 417 // that we do not get the bad port number again. |
| 418 intptr_t new_fd = CreateBindListen(addr, 0, backlog, v6_only); | 418 intptr_t new_fd = CreateBindListen(addr, 0, backlog, v6_only); |
| 419 int err = errno; | 419 int err = errno; |
| 420 VOID_TEMP_FAILURE_RETRY(close(fd)); | 420 VOID_TEMP_FAILURE_RETRY(close(fd)); |
| 421 errno = err; | 421 errno = err; |
| 422 return new_fd; | 422 return new_fd; |
| 423 } | 423 } |
| 424 | 424 |
| 425 if (TEMP_FAILURE_RETRY(listen(fd, backlog > 0 ? backlog : SOMAXCONN)) != 0) { | 425 if (TEMP_FAILURE_RETRY(listen(fd, backlog > 0 ? backlog : SOMAXCONN)) != 0) { |
| 426 TEMP_FAILURE_RETRY(close(fd)); | 426 VOID_TEMP_FAILURE_RETRY(close(fd)); |
| 427 return -1; | 427 return -1; |
| 428 } | 428 } |
| 429 | 429 |
| 430 Socket::SetNonBlocking(fd); | 430 Socket::SetNonBlocking(fd); |
| 431 return fd; | 431 return fd; |
| 432 } | 432 } |
| 433 | 433 |
| 434 | 434 |
| 435 static bool IsTemporaryAcceptError(int error) { | 435 static bool IsTemporaryAcceptError(int error) { |
| 436 // On Linux a number of protocol errors should be treated as EAGAIN. | 436 // On Linux a number of protocol errors should be treated as EAGAIN. |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 613 mreq.gr_interface = interfaceIndex; | 613 mreq.gr_interface = interfaceIndex; |
| 614 memmove(&mreq.gr_group, &addr->ss, SocketAddress::GetAddrLength(addr)); | 614 memmove(&mreq.gr_group, &addr->ss, SocketAddress::GetAddrLength(addr)); |
| 615 return TEMP_FAILURE_RETRY(setsockopt( | 615 return TEMP_FAILURE_RETRY(setsockopt( |
| 616 fd, proto, MCAST_LEAVE_GROUP, &mreq, sizeof(mreq))) == 0; | 616 fd, proto, MCAST_LEAVE_GROUP, &mreq, sizeof(mreq))) == 0; |
| 617 } | 617 } |
| 618 | 618 |
| 619 } // namespace bin | 619 } // namespace bin |
| 620 } // namespace dart | 620 } // namespace dart |
| 621 | 621 |
| 622 #endif // defined(TARGET_OS_LINUX) | 622 #endif // defined(TARGET_OS_LINUX) |
| OLD | NEW |