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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 | 96 |
97 return Socket::Connect(fd, addr, port); | 97 return Socket::Connect(fd, addr, port); |
98 } | 98 } |
99 | 99 |
100 | 100 |
101 intptr_t Socket::Available(intptr_t fd) { | 101 intptr_t Socket::Available(intptr_t fd) { |
102 return FDUtils::AvailableBytes(fd); | 102 return FDUtils::AvailableBytes(fd); |
103 } | 103 } |
104 | 104 |
105 | 105 |
106 int Socket::Read(intptr_t fd, void* buffer, intptr_t num_bytes) { | 106 intptr_t Socket::Read(intptr_t fd, void* buffer, intptr_t num_bytes) { |
107 ASSERT(fd >= 0); | 107 ASSERT(fd >= 0); |
108 ssize_t read_bytes = TEMP_FAILURE_RETRY(read(fd, buffer, num_bytes)); | 108 ssize_t read_bytes = TEMP_FAILURE_RETRY(read(fd, buffer, num_bytes)); |
109 ASSERT(EAGAIN == EWOULDBLOCK); | 109 ASSERT(EAGAIN == EWOULDBLOCK); |
110 if (read_bytes == -1 && errno == EWOULDBLOCK) { | 110 if (read_bytes == -1 && errno == EWOULDBLOCK) { |
111 // If the read would block we need to retry and therefore return 0 | 111 // If the read would block we need to retry and therefore return 0 |
112 // as the number of bytes written. | 112 // as the number of bytes written. |
113 read_bytes = 0; | 113 read_bytes = 0; |
114 } | 114 } |
115 return read_bytes; | 115 return read_bytes; |
116 } | 116 } |
117 | 117 |
118 | 118 |
119 int Socket::RecvFrom(intptr_t fd, void* buffer, intptr_t num_bytes, | 119 intptr_t Socket::RecvFrom(intptr_t fd, void* buffer, intptr_t num_bytes, |
120 RawAddr* addr) { | 120 RawAddr* addr) { |
121 ASSERT(fd >= 0); | 121 ASSERT(fd >= 0); |
122 socklen_t addr_len = sizeof(addr->ss); | 122 socklen_t addr_len = sizeof(addr->ss); |
123 ssize_t read_bytes = TEMP_FAILURE_RETRY( | 123 ssize_t read_bytes = TEMP_FAILURE_RETRY( |
124 recvfrom(fd, buffer, num_bytes, 0, &addr->addr, &addr_len)); | 124 recvfrom(fd, buffer, num_bytes, 0, &addr->addr, &addr_len)); |
125 if (read_bytes == -1 && errno == EWOULDBLOCK) { | 125 if (read_bytes == -1 && errno == EWOULDBLOCK) { |
126 // If the read would block we need to retry and therefore return 0 | 126 // If the read would block we need to retry and therefore return 0 |
127 // as the number of bytes written. | 127 // as the number of bytes written. |
128 read_bytes = 0; | 128 read_bytes = 0; |
129 } | 129 } |
130 return read_bytes; | 130 return read_bytes; |
131 } | 131 } |
132 | 132 |
133 | 133 |
134 int Socket::Write(intptr_t fd, const void* buffer, intptr_t num_bytes) { | 134 intptr_t Socket::Write(intptr_t fd, const void* buffer, intptr_t num_bytes) { |
135 ASSERT(fd >= 0); | 135 ASSERT(fd >= 0); |
136 ssize_t written_bytes = TEMP_FAILURE_RETRY(write(fd, buffer, num_bytes)); | 136 ssize_t written_bytes = TEMP_FAILURE_RETRY(write(fd, buffer, num_bytes)); |
137 ASSERT(EAGAIN == EWOULDBLOCK); | 137 ASSERT(EAGAIN == EWOULDBLOCK); |
138 if (written_bytes == -1 && errno == EWOULDBLOCK) { | 138 if (written_bytes == -1 && errno == EWOULDBLOCK) { |
139 // If the would block we need to retry and therefore return 0 as | 139 // If the would block we need to retry and therefore return 0 as |
140 // the number of bytes written. | 140 // the number of bytes written. |
141 written_bytes = 0; | 141 written_bytes = 0; |
142 } | 142 } |
143 return written_bytes; | 143 return written_bytes; |
144 } | 144 } |
145 | 145 |
146 | 146 |
147 int Socket::SendTo(intptr_t fd, const void* buffer, intptr_t num_bytes, | 147 intptr_t Socket::SendTo(intptr_t fd, const void* buffer, intptr_t num_bytes, |
148 RawAddr addr) { | 148 RawAddr addr) { |
149 ASSERT(fd >= 0); | 149 ASSERT(fd >= 0); |
150 ssize_t written_bytes = TEMP_FAILURE_RETRY( | 150 ssize_t written_bytes = TEMP_FAILURE_RETRY( |
151 sendto(fd, buffer, num_bytes, 0, | 151 sendto(fd, buffer, num_bytes, 0, |
152 &addr.addr, SocketAddress::GetAddrLength(&addr))); | 152 &addr.addr, SocketAddress::GetAddrLength(&addr))); |
153 ASSERT(EAGAIN == EWOULDBLOCK); | 153 ASSERT(EAGAIN == EWOULDBLOCK); |
154 if (written_bytes == -1 && errno == EWOULDBLOCK) { | 154 if (written_bytes == -1 && errno == EWOULDBLOCK) { |
155 // If the would block we need to retry and therefore return 0 as | 155 // If the would block we need to retry and therefore return 0 as |
156 // the number of bytes written. | 156 // the number of bytes written. |
157 written_bytes = 0; | 157 written_bytes = 0; |
(...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
613 | 613 |
614 bool Socket::LeaveMulticast( | 614 bool Socket::LeaveMulticast( |
615 intptr_t fd, RawAddr* addr, RawAddr* interface, int interfaceIndex) { | 615 intptr_t fd, RawAddr* addr, RawAddr* interface, int interfaceIndex) { |
616 return JoinOrLeaveMulticast(fd, addr, interface, interfaceIndex, false); | 616 return JoinOrLeaveMulticast(fd, addr, interface, interfaceIndex, false); |
617 } | 617 } |
618 | 618 |
619 } // namespace bin | 619 } // namespace bin |
620 } // namespace dart | 620 } // namespace dart |
621 | 621 |
622 #endif // defined(TARGET_OS_MACOS) | 622 #endif // defined(TARGET_OS_MACOS) |
OLD | NEW |