| 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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 return true; | 50 return true; |
| 51 } | 51 } |
| 52 | 52 |
| 53 | 53 |
| 54 bool Socket::Initialize() { | 54 bool Socket::Initialize() { |
| 55 // Nothing to do on Mac OS. | 55 // Nothing to do on Mac OS. |
| 56 return true; | 56 return true; |
| 57 } | 57 } |
| 58 | 58 |
| 59 | 59 |
| 60 intptr_t Socket::Create(RawAddr addr) { | 60 static intptr_t Create(RawAddr addr) { |
| 61 intptr_t fd; | 61 intptr_t fd; |
| 62 fd = NO_RETRY_EXPECTED(socket(addr.ss.ss_family, SOCK_STREAM, 0)); | 62 fd = NO_RETRY_EXPECTED(socket(addr.ss.ss_family, SOCK_STREAM, 0)); |
| 63 if (fd < 0) { | 63 if (fd < 0) { |
| 64 return -1; | 64 return -1; |
| 65 } | 65 } |
| 66 FDUtils::SetCloseOnExec(fd); | 66 FDUtils::SetCloseOnExec(fd); |
| 67 return fd; | 67 return fd; |
| 68 } | 68 } |
| 69 | 69 |
| 70 | 70 |
| 71 intptr_t Socket::Connect(intptr_t fd, RawAddr addr, const intptr_t port) { | 71 static intptr_t Connect(intptr_t fd, RawAddr addr, const intptr_t port) { |
| 72 SocketAddress::SetAddrPort(&addr, port); | 72 SocketAddress::SetAddrPort(&addr, port); |
| 73 intptr_t result = TEMP_FAILURE_RETRY( | 73 intptr_t result = TEMP_FAILURE_RETRY( |
| 74 connect(fd, &addr.addr, SocketAddress::GetAddrLength(&addr))); | 74 connect(fd, &addr.addr, SocketAddress::GetAddrLength(&addr))); |
| 75 if (result == 0 || errno == EINPROGRESS) { | 75 if (result == 0 || errno == EINPROGRESS) { |
| 76 return fd; | 76 return fd; |
| 77 } | 77 } |
| 78 VOID_TEMP_FAILURE_RETRY(close(fd)); | 78 VOID_TEMP_FAILURE_RETRY(close(fd)); |
| 79 return -1; | 79 return -1; |
| 80 } | 80 } |
| 81 | 81 |
| 82 | 82 |
| 83 intptr_t Socket::CreateConnect(RawAddr addr, const intptr_t port) { | 83 intptr_t Socket::CreateConnect(const RawAddr& addr, const intptr_t port) { |
| 84 intptr_t fd = Socket::Create(addr); | 84 intptr_t fd = Create(addr); |
| 85 if (fd < 0) { | 85 if (fd < 0) { |
| 86 return fd; | 86 return fd; |
| 87 } | 87 } |
| 88 | 88 |
| 89 FDUtils::SetNonBlocking(fd); | 89 FDUtils::SetNonBlocking(fd); |
| 90 | 90 |
| 91 return Socket::Connect(fd, addr, port); | 91 return Connect(fd, addr, port); |
| 92 } | 92 } |
| 93 | 93 |
| 94 | 94 |
| 95 intptr_t Socket::CreateBindConnect(const RawAddr& addr, |
| 96 const intptr_t port, |
| 97 const RawAddr& source_addr) { |
| 98 intptr_t fd = Create(addr); |
| 99 if (fd < 0) { |
| 100 return fd; |
| 101 } |
| 102 |
| 103 intptr_t result = TEMP_FAILURE_RETRY( |
| 104 bind(fd, &source_addr.addr, SocketAddress::GetAddrLength(&source_addr))); |
| 105 if (result != 0 && errno != EINPROGRESS) { |
| 106 VOID_TEMP_FAILURE_RETRY(close(fd)); |
| 107 return -1; |
| 108 } |
| 109 |
| 110 return Connect(fd, addr, port); |
| 111 } |
| 112 |
| 113 |
| 95 intptr_t Socket::Available(intptr_t fd) { | 114 intptr_t Socket::Available(intptr_t fd) { |
| 96 return FDUtils::AvailableBytes(fd); | 115 return FDUtils::AvailableBytes(fd); |
| 97 } | 116 } |
| 98 | 117 |
| 99 | 118 |
| 100 intptr_t Socket::Read(intptr_t fd, void* buffer, intptr_t num_bytes) { | 119 intptr_t Socket::Read(intptr_t fd, void* buffer, intptr_t num_bytes) { |
| 101 ASSERT(fd >= 0); | 120 ASSERT(fd >= 0); |
| 102 ssize_t read_bytes = TEMP_FAILURE_RETRY(read(fd, buffer, num_bytes)); | 121 ssize_t read_bytes = TEMP_FAILURE_RETRY(read(fd, buffer, num_bytes)); |
| 103 ASSERT(EAGAIN == EWOULDBLOCK); | 122 ASSERT(EAGAIN == EWOULDBLOCK); |
| 104 if (read_bytes == -1 && errno == EWOULDBLOCK) { | 123 if (read_bytes == -1 && errno == EWOULDBLOCK) { |
| (...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 594 | 613 |
| 595 bool Socket::LeaveMulticast( | 614 bool Socket::LeaveMulticast( |
| 596 intptr_t fd, RawAddr* addr, RawAddr* interface, int interfaceIndex) { | 615 intptr_t fd, RawAddr* addr, RawAddr* interface, int interfaceIndex) { |
| 597 return JoinOrLeaveMulticast(fd, addr, interface, interfaceIndex, false); | 616 return JoinOrLeaveMulticast(fd, addr, interface, interfaceIndex, false); |
| 598 } | 617 } |
| 599 | 618 |
| 600 } // namespace bin | 619 } // namespace bin |
| 601 } // namespace dart | 620 } // namespace dart |
| 602 | 621 |
| 603 #endif // defined(TARGET_OS_MACOS) | 622 #endif // defined(TARGET_OS_MACOS) |
| OLD | NEW |