Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(489)

Side by Side Diff: runtime/bin/socket_common_fuchsia.cc

Issue 2780063002: Pulled a significant portion of Socket implementation into BaseSocket in order to prepare for the s… (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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 #if !defined(DART_IO_DISABLED) 5 #if !defined(DART_IO_DISABLED)
6 6
7 #include "platform/globals.h" 7 #include "platform/globals.h"
8 #if defined(TARGET_OS_FUCHSIA) 8 #if defined(TARGET_OS_FUCHSIA)
9 9
10 #include "bin/socket.h" 10 #include "bin/socket.h"
11 #include "bin/socket_fuchsia.h" 11 #include "bin/socket_common_fuchsia.h"
12 12
13 #include <errno.h> // NOLINT 13 #include <errno.h> // NOLINT
14 #include <fcntl.h> // NOLINT 14 #include <fcntl.h> // NOLINT
15 #include <ifaddrs.h> // NOLINT 15 #include <ifaddrs.h> // NOLINT
16 #include <net/if.h> // NOLINT 16 #include <net/if.h> // NOLINT
17 #include <netinet/tcp.h> // NOLINT 17 #include <netinet/tcp.h> // NOLINT
18 #include <stdio.h> // NOLINT 18 #include <stdio.h> // NOLINT
19 #include <stdlib.h> // NOLINT 19 #include <stdlib.h> // NOLINT
20 #include <string.h> // NOLINT 20 #include <string.h> // NOLINT
21 #include <sys/ioctl.h> // NOLINT 21 #include <sys/ioctl.h> // NOLINT
(...skipping 26 matching lines...) Expand all
48 #else 48 #else
49 #define LOG_ERR(msg, ...) 49 #define LOG_ERR(msg, ...)
50 #define LOG_INFO(msg, ...) 50 #define LOG_INFO(msg, ...)
51 #endif // defined(SOCKET_LOG_INFO) || defined(SOCKET_LOG_ERROR) 51 #endif // defined(SOCKET_LOG_INFO) || defined(SOCKET_LOG_ERROR)
52 52
53 namespace dart { 53 namespace dart {
54 namespace bin { 54 namespace bin {
55 55
56 SocketAddress::SocketAddress(struct sockaddr* sa) { 56 SocketAddress::SocketAddress(struct sockaddr* sa) {
57 ASSERT(INET6_ADDRSTRLEN >= INET_ADDRSTRLEN); 57 ASSERT(INET6_ADDRSTRLEN >= INET_ADDRSTRLEN);
58 if (!Socket::FormatNumericAddress(*reinterpret_cast<RawAddr*>(sa), as_string_, 58 if (!BaseSocket::FormatNumericAddress(*reinterpret_cast<RawAddr*>(sa),
59 INET6_ADDRSTRLEN)) { 59 as_string_, INET6_ADDRSTRLEN)) {
60 as_string_[0] = 0; 60 as_string_[0] = 0;
61 } 61 }
62 socklen_t salen = GetAddrLength(*reinterpret_cast<RawAddr*>(sa)); 62 socklen_t salen = GetAddrLength(*reinterpret_cast<RawAddr*>(sa));
63 memmove(reinterpret_cast<void*>(&addr_), sa, salen); 63 memmove(reinterpret_cast<void*>(&addr_), sa, salen);
64 } 64 }
65 65
66 66
67 bool Socket::FormatNumericAddress(const RawAddr& addr, char* address, int len) { 67 bool BaseSocket::FormatNumericAddress(const RawAddr& addr,
68 char* address,
69 int len) {
68 socklen_t salen = SocketAddress::GetAddrLength(addr); 70 socklen_t salen = SocketAddress::GetAddrLength(addr);
69 LOG_INFO("Socket::FormatNumericAddress: calling getnameinfo\n"); 71 LOG_INFO("BaseSocket::FormatNumericAddress: calling getnameinfo\n");
70 return (NO_RETRY_EXPECTED(getnameinfo(&addr.addr, salen, address, len, NULL, 72 return (NO_RETRY_EXPECTED(getnameinfo(&addr.addr, salen, address, len, NULL,
71 0, NI_NUMERICHOST) == 0)); 73 0, NI_NUMERICHOST) == 0));
72 } 74 }
73 75
74 76
75 bool Socket::Initialize() { 77 bool BaseSocket::Initialize() {
76 // Nothing to do on Fuchsia. 78 // Nothing to do on Fuchsia.
77 return true; 79 return true;
78 } 80 }
79 81
80 82
81 static intptr_t Create(const RawAddr& addr) { 83 static intptr_t Create(const RawAddr& addr) {
82 LOG_INFO("Create: calling socket(SOCK_STREAM)\n"); 84 LOG_INFO("Create: calling socket(SOCK_STREAM)\n");
83 intptr_t fd = NO_RETRY_EXPECTED(socket(addr.ss.ss_family, SOCK_STREAM, 0)); 85 intptr_t fd = NO_RETRY_EXPECTED(socket(addr.ss.ss_family, SOCK_STREAM, 0));
84 if (fd < 0) { 86 if (fd < 0) {
85 LOG_ERR("Create: socket(SOCK_STREAM) failed\n"); 87 LOG_ERR("Create: socket(SOCK_STREAM) failed\n");
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 LOG_ERR("CreateConnect: FDUtils::SetNonBlocking(%ld) failed\n", fd); 119 LOG_ERR("CreateConnect: FDUtils::SetNonBlocking(%ld) failed\n", fd);
118 FDUtils::SaveErrorAndClose(fd); 120 FDUtils::SaveErrorAndClose(fd);
119 return -1; 121 return -1;
120 } 122 }
121 return Connect(fd, addr); 123 return Connect(fd, addr);
122 } 124 }
123 125
124 126
125 intptr_t Socket::CreateBindConnect(const RawAddr& addr, 127 intptr_t Socket::CreateBindConnect(const RawAddr& addr,
126 const RawAddr& source_addr) { 128 const RawAddr& source_addr) {
127 LOG_ERR("Socket::CreateBindConnect is unimplemented\n"); 129 LOG_ERR("BaseSocket::CreateBindConnect is unimplemented\n");
128 UNIMPLEMENTED(); 130 UNIMPLEMENTED();
129 return -1; 131 return -1;
130 } 132 }
131 133
132 134
133 bool Socket::IsBindError(intptr_t error_number) { 135 bool BaseSocket::IsBindError(intptr_t error_number) {
134 return error_number == EADDRINUSE || error_number == EADDRNOTAVAIL || 136 return error_number == EADDRINUSE || error_number == EADDRNOTAVAIL ||
135 error_number == EINVAL; 137 error_number == EINVAL;
136 } 138 }
137 139
138 140
139 intptr_t Socket::Available(intptr_t fd) { 141 intptr_t BaseSocket::Available(intptr_t fd) {
140 intptr_t available = FDUtils::AvailableBytes(fd); 142 intptr_t available = FDUtils::AvailableBytes(fd);
141 LOG_INFO("Socket::Available(%ld) = %ld\n", fd, available); 143 LOG_INFO("BaseSocket::Available(%ld) = %ld\n", fd, available);
142 return available; 144 return available;
143 } 145 }
144 146
145 147
146 intptr_t Socket::Read(intptr_t fd, void* buffer, intptr_t num_bytes) { 148 intptr_t BaseSocket::Read(intptr_t fd, void* buffer, intptr_t num_bytes) {
147 ASSERT(fd >= 0); 149 ASSERT(fd >= 0);
148 LOG_INFO("Socket::Read: calling read(%ld, %p, %ld)\n", fd, buffer, num_bytes); 150 LOG_INFO("BaseSocket::Read: calling read(%ld, %p, %ld)\n", fd, buffer,
151 num_bytes);
149 ssize_t read_bytes = NO_RETRY_EXPECTED(read(fd, buffer, num_bytes)); 152 ssize_t read_bytes = NO_RETRY_EXPECTED(read(fd, buffer, num_bytes));
150 ASSERT(EAGAIN == EWOULDBLOCK); 153 ASSERT(EAGAIN == EWOULDBLOCK);
151 if ((read_bytes == -1) && (errno == EWOULDBLOCK)) { 154 if ((read_bytes == -1) && (errno == EWOULDBLOCK)) {
152 // If the read would block we need to retry and therefore return 0 155 // If the read would block we need to retry and therefore return 0
153 // as the number of bytes written. 156 // as the number of bytes written.
154 read_bytes = 0; 157 read_bytes = 0;
155 } else if (read_bytes == -1) { 158 } else if (read_bytes == -1) {
156 LOG_ERR("Socket::Read: read(%ld, %p, %ld) failed\n", fd, buffer, num_bytes); 159 LOG_ERR("BaseSocket::Read: read(%ld, %p, %ld) failed\n", fd, buffer,
160 num_bytes);
157 } else { 161 } else {
158 LOG_INFO("Socket::Read: read(%ld, %p, %ld) succeeded\n", fd, buffer, 162 LOG_INFO("BaseSocket::Read: read(%ld, %p, %ld) succeeded\n", fd, buffer,
159 num_bytes); 163 num_bytes);
160 } 164 }
161 return read_bytes; 165 return read_bytes;
162 } 166 }
163 167
164 168
165 intptr_t Socket::RecvFrom(intptr_t fd, 169 intptr_t BaseSocket::RecvFrom(intptr_t fd,
166 void* buffer, 170 void* buffer,
167 intptr_t num_bytes, 171 intptr_t num_bytes,
168 RawAddr* addr) { 172 RawAddr* addr) {
169 LOG_ERR("Socket::RecvFrom is unimplemented\n"); 173 LOG_ERR("BaseSocket::RecvFrom is unimplemented\n");
170 UNIMPLEMENTED(); 174 UNIMPLEMENTED();
171 return -1; 175 return -1;
172 } 176 }
173 177
174 178
175 intptr_t Socket::Write(intptr_t fd, const void* buffer, intptr_t num_bytes) { 179 intptr_t BaseSocket::Write(intptr_t fd,
180 const void* buffer,
181 intptr_t num_bytes) {
176 ASSERT(fd >= 0); 182 ASSERT(fd >= 0);
177 LOG_INFO("Socket::Write: calling write(%ld, %p, %ld)\n", fd, buffer, 183 LOG_INFO("BaseSocket::Write: calling write(%ld, %p, %ld)\n", fd, buffer,
178 num_bytes); 184 num_bytes);
179 ssize_t written_bytes = NO_RETRY_EXPECTED(write(fd, buffer, num_bytes)); 185 ssize_t written_bytes = NO_RETRY_EXPECTED(write(fd, buffer, num_bytes));
180 ASSERT(EAGAIN == EWOULDBLOCK); 186 ASSERT(EAGAIN == EWOULDBLOCK);
181 if ((written_bytes == -1) && (errno == EWOULDBLOCK)) { 187 if ((written_bytes == -1) && (errno == EWOULDBLOCK)) {
182 // If the would block we need to retry and therefore return 0 as 188 // If the would block we need to retry and therefore return 0 as
183 // the number of bytes written. 189 // the number of bytes written.
184 written_bytes = 0; 190 written_bytes = 0;
185 } else if (written_bytes == -1) { 191 } else if (written_bytes == -1) {
186 LOG_ERR("Socket::Write: write(%ld, %p, %ld) failed\n", fd, buffer, 192 LOG_ERR("BaseSocket::Write: write(%ld, %p, %ld) failed\n", fd, buffer,
187 num_bytes); 193 num_bytes);
188 } else { 194 } else {
189 LOG_INFO("Socket::Write: write(%ld, %p, %ld) succeeded\n", fd, buffer, 195 LOG_INFO("BaseSocket::Write: write(%ld, %p, %ld) succeeded\n", fd, buffer,
190 num_bytes); 196 num_bytes);
191 } 197 }
192 return written_bytes; 198 return written_bytes;
193 } 199 }
194 200
195 201
196 intptr_t Socket::SendTo(intptr_t fd, 202 intptr_t BaseSocket::SendTo(intptr_t fd,
197 const void* buffer, 203 const void* buffer,
198 intptr_t num_bytes, 204 intptr_t num_bytes,
199 const RawAddr& addr) { 205 const RawAddr& addr) {
200 LOG_ERR("Socket::SendTo is unimplemented\n"); 206 LOG_ERR("BaseSocket::SendTo is unimplemented\n");
201 UNIMPLEMENTED(); 207 UNIMPLEMENTED();
202 return -1; 208 return -1;
203 } 209 }
204 210
205 211
206 intptr_t Socket::GetPort(intptr_t fd) { 212 intptr_t BaseSocket::GetPort(intptr_t fd) {
207 ASSERT(fd >= 0); 213 ASSERT(fd >= 0);
208 RawAddr raw; 214 RawAddr raw;
209 socklen_t size = sizeof(raw); 215 socklen_t size = sizeof(raw);
210 LOG_INFO("Socket::GetPort: calling getsockname(%ld)\n", fd); 216 LOG_INFO("BaseSocket::GetPort: calling getsockname(%ld)\n", fd);
211 if (NO_RETRY_EXPECTED(getsockname(fd, &raw.addr, &size))) { 217 if (NO_RETRY_EXPECTED(getsockname(fd, &raw.addr, &size))) {
212 return 0; 218 return 0;
213 } 219 }
214 return SocketAddress::GetAddrPort(raw); 220 return SocketAddress::GetAddrPort(raw);
215 } 221 }
216 222
217 223
218 SocketAddress* Socket::GetRemotePeer(intptr_t fd, intptr_t* port) { 224 SocketAddress* BaseSocket::GetRemotePeer(intptr_t fd, intptr_t* port) {
219 ASSERT(fd >= 0); 225 ASSERT(fd >= 0);
220 RawAddr raw; 226 RawAddr raw;
221 socklen_t size = sizeof(raw); 227 socklen_t size = sizeof(raw);
222 if (NO_RETRY_EXPECTED(getpeername(fd, &raw.addr, &size))) { 228 if (NO_RETRY_EXPECTED(getpeername(fd, &raw.addr, &size))) {
223 return NULL; 229 return NULL;
224 } 230 }
225 *port = SocketAddress::GetAddrPort(raw); 231 *port = SocketAddress::GetAddrPort(raw);
226 return new SocketAddress(&raw.addr); 232 return new SocketAddress(&raw.addr);
227 } 233 }
228 234
229 235
230 void Socket::GetError(intptr_t fd, OSError* os_error) { 236 void BaseSocket::GetError(intptr_t fd, OSError* os_error) {
231 LOG_ERR("Socket::GetError is unimplemented\n"); 237 LOG_ERR("BaseSocket::GetError is unimplemented\n");
232 UNIMPLEMENTED(); 238 UNIMPLEMENTED();
233 } 239 }
234 240
235 241
236 int Socket::GetType(intptr_t fd) { 242 int BaseSocket::GetType(intptr_t fd) {
237 LOG_ERR("Socket::GetType is unimplemented\n"); 243 LOG_ERR("BaseSocket::GetType is unimplemented\n");
238 UNIMPLEMENTED(); 244 UNIMPLEMENTED();
239 return File::kOther; 245 return File::kOther;
240 } 246 }
241 247
242 248
243 intptr_t Socket::GetStdioHandle(intptr_t num) { 249 intptr_t BaseSocket::GetStdioHandle(intptr_t num) {
244 LOG_ERR("Socket::GetStdioHandle is unimplemented\n"); 250 LOG_ERR("BaseSocket::GetStdioHandle is unimplemented\n");
245 UNIMPLEMENTED(); 251 UNIMPLEMENTED();
246 return num; 252 return num;
247 } 253 }
248 254
249 255
250 AddressList<SocketAddress>* Socket::LookupAddress(const char* host, 256 AddressList<SocketAddress>* BaseSocket::LookupAddress(const char* host,
251 int type, 257 int type,
252 OSError** os_error) { 258 OSError** os_error) {
253 // Perform a name lookup for a host name. 259 // Perform a name lookup for a host name.
254 struct addrinfo hints; 260 struct addrinfo hints;
255 memset(&hints, 0, sizeof(hints)); 261 memset(&hints, 0, sizeof(hints));
256 hints.ai_family = SocketAddress::FromType(type); 262 hints.ai_family = SocketAddress::FromType(type);
257 hints.ai_socktype = SOCK_STREAM; 263 hints.ai_socktype = SOCK_STREAM;
258 hints.ai_flags = AI_ADDRCONFIG; 264 hints.ai_flags = AI_ADDRCONFIG;
259 hints.ai_protocol = IPPROTO_TCP; 265 hints.ai_protocol = IPPROTO_TCP;
260 struct addrinfo* info = NULL; 266 struct addrinfo* info = NULL;
261 LOG_INFO("Socket::LookupAddress: calling getaddrinfo\n"); 267 LOG_INFO("BaseSocket::LookupAddress: calling getaddrinfo\n");
262 int status = NO_RETRY_EXPECTED(getaddrinfo(host, 0, &hints, &info)); 268 int status = NO_RETRY_EXPECTED(getaddrinfo(host, 0, &hints, &info));
263 if (status != 0) { 269 if (status != 0) {
264 // We failed, try without AI_ADDRCONFIG. This can happen when looking up 270 // We failed, try without AI_ADDRCONFIG. This can happen when looking up
265 // e.g. '::1', when there are no global IPv6 addresses. 271 // e.g. '::1', when there are no global IPv6 addresses.
266 hints.ai_flags = 0; 272 hints.ai_flags = 0;
267 LOG_INFO("Socket::LookupAddress: calling getaddrinfo again\n"); 273 LOG_INFO("BaseSocket::LookupAddress: calling getaddrinfo again\n");
268 status = NO_RETRY_EXPECTED(getaddrinfo(host, 0, &hints, &info)); 274 status = NO_RETRY_EXPECTED(getaddrinfo(host, 0, &hints, &info));
269 if (status != 0) { 275 if (status != 0) {
270 ASSERT(*os_error == NULL); 276 ASSERT(*os_error == NULL);
271 *os_error = 277 *os_error =
272 new OSError(status, gai_strerror(status), OSError::kGetAddressInfo); 278 new OSError(status, gai_strerror(status), OSError::kGetAddressInfo);
273 return NULL; 279 return NULL;
274 } 280 }
275 } 281 }
276 intptr_t count = 0; 282 intptr_t count = 0;
277 for (struct addrinfo* c = info; c != NULL; c = c->ai_next) { 283 for (struct addrinfo* c = info; c != NULL; c = c->ai_next) {
278 if ((c->ai_family == AF_INET) || (c->ai_family == AF_INET6)) { 284 if ((c->ai_family == AF_INET) || (c->ai_family == AF_INET6)) {
279 count++; 285 count++;
280 } 286 }
281 } 287 }
282 intptr_t i = 0; 288 intptr_t i = 0;
283 AddressList<SocketAddress>* addresses = new AddressList<SocketAddress>(count); 289 AddressList<SocketAddress>* addresses = new AddressList<SocketAddress>(count);
284 for (struct addrinfo* c = info; c != NULL; c = c->ai_next) { 290 for (struct addrinfo* c = info; c != NULL; c = c->ai_next) {
285 if ((c->ai_family == AF_INET) || (c->ai_family == AF_INET6)) { 291 if ((c->ai_family == AF_INET) || (c->ai_family == AF_INET6)) {
286 addresses->SetAt(i, new SocketAddress(c->ai_addr)); 292 addresses->SetAt(i, new SocketAddress(c->ai_addr));
287 i++; 293 i++;
288 } 294 }
289 } 295 }
290 freeaddrinfo(info); 296 freeaddrinfo(info);
291 return addresses; 297 return addresses;
292 } 298 }
293 299
294 300
295 bool Socket::ReverseLookup(const RawAddr& addr, 301 bool BaseSocket::ReverseLookup(const RawAddr& addr,
296 char* host, 302 char* host,
297 intptr_t host_len, 303 intptr_t host_len,
298 OSError** os_error) { 304 OSError** os_error) {
299 LOG_ERR("Socket::ReverseLookup is unimplemented\n"); 305 LOG_ERR("BaseSocket::ReverseLookup is unimplemented\n");
300 UNIMPLEMENTED(); 306 UNIMPLEMENTED();
301 return false; 307 return false;
302 } 308 }
303 309
304 310
305 bool Socket::ParseAddress(int type, const char* address, RawAddr* addr) { 311 bool BaseSocket::ParseAddress(int type, const char* address, RawAddr* addr) {
306 int result; 312 int result;
307 if (type == SocketAddress::TYPE_IPV4) { 313 if (type == SocketAddress::TYPE_IPV4) {
308 result = NO_RETRY_EXPECTED(inet_pton(AF_INET, address, &addr->in.sin_addr)); 314 result = NO_RETRY_EXPECTED(inet_pton(AF_INET, address, &addr->in.sin_addr));
309 } else { 315 } else {
310 ASSERT(type == SocketAddress::TYPE_IPV6); 316 ASSERT(type == SocketAddress::TYPE_IPV6);
311 result = 317 result =
312 NO_RETRY_EXPECTED(inet_pton(AF_INET6, address, &addr->in6.sin6_addr)); 318 NO_RETRY_EXPECTED(inet_pton(AF_INET6, address, &addr->in6.sin6_addr));
313 } 319 }
314 return (result == 1); 320 return (result == 1);
315 } 321 }
316 322
317 323
318 intptr_t Socket::CreateBindDatagram(const RawAddr& addr, bool reuseAddress) { 324 intptr_t Socket::CreateBindDatagram(const RawAddr& addr, bool reuseAddress) {
319 LOG_ERR("Socket::CreateBindDatagram is unimplemented\n"); 325 LOG_ERR("BaseSocket::CreateBindDatagram is unimplemented\n");
320 UNIMPLEMENTED(); 326 UNIMPLEMENTED();
321 return -1; 327 return -1;
322 } 328 }
323 329
324 330
325 bool Socket::ListInterfacesSupported() { 331 bool BaseSocket::ListInterfacesSupported() {
326 return false; 332 return false;
327 } 333 }
328 334
329 335
330 AddressList<InterfaceSocketAddress>* Socket::ListInterfaces( 336 AddressList<InterfaceSocketAddress>* BaseSocket::ListInterfaces(
331 int type, 337 int type,
332 OSError** os_error) { 338 OSError** os_error) {
333 UNIMPLEMENTED(); 339 UNIMPLEMENTED();
334 return NULL; 340 return NULL;
335 } 341 }
336 342
337 343
338 intptr_t ServerSocket::CreateBindListen(const RawAddr& addr, 344 intptr_t ServerSocket::CreateBindListen(const RawAddr& addr,
339 intptr_t backlog, 345 intptr_t backlog,
340 bool v6_only) { 346 bool v6_only) {
(...skipping 27 matching lines...) Expand all
368 if (NO_RETRY_EXPECTED( 374 if (NO_RETRY_EXPECTED(
369 bind(fd, &addr.addr, SocketAddress::GetAddrLength(addr))) < 0) { 375 bind(fd, &addr.addr, SocketAddress::GetAddrLength(addr))) < 0) {
370 LOG_ERR("ServerSocket::CreateBindListen: bind(%ld) failed\n", fd); 376 LOG_ERR("ServerSocket::CreateBindListen: bind(%ld) failed\n", fd);
371 FDUtils::SaveErrorAndClose(fd); 377 FDUtils::SaveErrorAndClose(fd);
372 return -1; 378 return -1;
373 } 379 }
374 LOG_INFO("ServerSocket::CreateBindListen: bind(%ld) succeeded\n", fd); 380 LOG_INFO("ServerSocket::CreateBindListen: bind(%ld) succeeded\n", fd);
375 381
376 // Test for invalid socket port 65535 (some browsers disallow it). 382 // Test for invalid socket port 65535 (some browsers disallow it).
377 if ((SocketAddress::GetAddrPort(addr) == 0) && 383 if ((SocketAddress::GetAddrPort(addr) == 0) &&
378 (Socket::GetPort(fd) == 65535)) { 384 (BaseSocket::GetPort(fd) == 65535)) {
379 // Don't close the socket until we have created a new socket, ensuring 385 // Don't close the socket until we have created a new socket, ensuring
380 // that we do not get the bad port number again. 386 // that we do not get the bad port number again.
381 intptr_t new_fd = CreateBindListen(addr, backlog, v6_only); 387 intptr_t new_fd = CreateBindListen(addr, backlog, v6_only);
382 FDUtils::SaveErrorAndClose(fd); 388 FDUtils::SaveErrorAndClose(fd);
383 return new_fd; 389 return new_fd;
384 } 390 }
385 391
386 LOG_INFO("ServerSocket::CreateBindListen: calling listen(%ld)\n", fd); 392 LOG_INFO("ServerSocket::CreateBindListen: calling listen(%ld)\n", fd);
387 if (NO_RETRY_EXPECTED(listen(fd, backlog > 0 ? backlog : SOMAXCONN)) != 0) { 393 if (NO_RETRY_EXPECTED(listen(fd, backlog > 0 ? backlog : SOMAXCONN)) != 0) {
388 LOG_ERR("ServerSocket::CreateBindListen: listen failed(%ld)\n", fd); 394 LOG_ERR("ServerSocket::CreateBindListen: listen failed(%ld)\n", fd);
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 if (!FDUtils::SetNonBlocking(socket)) { 448 if (!FDUtils::SetNonBlocking(socket)) {
443 LOG_ERR("FDUtils::SetNonBlocking(%ld) failed\n", socket); 449 LOG_ERR("FDUtils::SetNonBlocking(%ld) failed\n", socket);
444 FDUtils::SaveErrorAndClose(socket); 450 FDUtils::SaveErrorAndClose(socket);
445 return -1; 451 return -1;
446 } 452 }
447 } 453 }
448 return socket; 454 return socket;
449 } 455 }
450 456
451 457
452 void Socket::Close(intptr_t fd) { 458 void BaseSocket::Close(intptr_t fd) {
453 ASSERT(fd >= 0); 459 ASSERT(fd >= 0);
454 NO_RETRY_EXPECTED(close(fd)); 460 NO_RETRY_EXPECTED(close(fd));
455 } 461 }
456 462
457 463
458 bool Socket::GetNoDelay(intptr_t fd, bool* enabled) { 464 bool BaseSocket::GetNoDelay(intptr_t fd, bool* enabled) {
459 LOG_ERR("Socket::GetNoDelay is unimplemented\n"); 465 LOG_ERR("BaseSocket::GetNoDelay is unimplemented\n");
460 UNIMPLEMENTED(); 466 UNIMPLEMENTED();
461 return false; 467 return false;
462 } 468 }
463 469
464 470
465 bool Socket::SetNoDelay(intptr_t fd, bool enabled) { 471 bool BaseSocket::SetNoDelay(intptr_t fd, bool enabled) {
466 int on = enabled ? 1 : 0; 472 int on = enabled ? 1 : 0;
467 return NO_RETRY_EXPECTED(setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, 473 return NO_RETRY_EXPECTED(setsockopt(fd, IPPROTO_TCP, TCP_NODELAY,
468 reinterpret_cast<char*>(&on), 474 reinterpret_cast<char*>(&on),
469 sizeof(on))) == 0; 475 sizeof(on))) == 0;
470 } 476 }
471 477
472 478
473 bool Socket::GetMulticastLoop(intptr_t fd, intptr_t protocol, bool* enabled) { 479 bool BaseSocket::GetMulticastLoop(intptr_t fd,
474 LOG_ERR("Socket::GetMulticastLoop is unimplemented\n"); 480 intptr_t protocol,
481 bool* enabled) {
482 LOG_ERR("BaseSocket::GetMulticastLoop is unimplemented\n");
475 UNIMPLEMENTED(); 483 UNIMPLEMENTED();
476 return false; 484 return false;
477 } 485 }
478 486
479 487
480 bool Socket::SetMulticastLoop(intptr_t fd, intptr_t protocol, bool enabled) { 488 bool BaseSocket::SetMulticastLoop(intptr_t fd,
481 LOG_ERR("Socket::SetMulticastLoop is unimplemented\n"); 489 intptr_t protocol,
490 bool enabled) {
491 LOG_ERR("BaseSocket::SetMulticastLoop is unimplemented\n");
482 UNIMPLEMENTED(); 492 UNIMPLEMENTED();
483 return false; 493 return false;
484 } 494 }
485 495
486 496
487 bool Socket::GetMulticastHops(intptr_t fd, intptr_t protocol, int* value) { 497 bool BaseSocket::GetMulticastHops(intptr_t fd, intptr_t protocol, int* value) {
488 LOG_ERR("Socket::GetMulticastHops is unimplemented\n"); 498 LOG_ERR("BaseSocket::GetMulticastHops is unimplemented\n");
489 UNIMPLEMENTED(); 499 UNIMPLEMENTED();
490 return false; 500 return false;
491 } 501 }
492 502
493 503
494 bool Socket::SetMulticastHops(intptr_t fd, intptr_t protocol, int value) { 504 bool BaseSocket::SetMulticastHops(intptr_t fd, intptr_t protocol, int value) {
495 LOG_ERR("Socket::SetMulticastHops is unimplemented\n"); 505 LOG_ERR("BaseSocket::SetMulticastHops is unimplemented\n");
496 UNIMPLEMENTED(); 506 UNIMPLEMENTED();
497 return false; 507 return false;
498 } 508 }
499 509
500 510
501 bool Socket::GetBroadcast(intptr_t fd, bool* enabled) { 511 bool BaseSocket::GetBroadcast(intptr_t fd, bool* enabled) {
502 LOG_ERR("Socket::GetBroadcast is unimplemented\n"); 512 LOG_ERR("BaseSocket::GetBroadcast is unimplemented\n");
503 UNIMPLEMENTED(); 513 UNIMPLEMENTED();
504 return false; 514 return false;
505 } 515 }
506 516
507 517
508 bool Socket::SetBroadcast(intptr_t fd, bool enabled) { 518 bool BaseSocket::SetBroadcast(intptr_t fd, bool enabled) {
509 LOG_ERR("Socket::SetBroadcast is unimplemented\n"); 519 LOG_ERR("BaseSocket::SetBroadcast is unimplemented\n");
510 UNIMPLEMENTED(); 520 UNIMPLEMENTED();
511 return false; 521 return false;
512 } 522 }
513 523
514 524
515 bool Socket::JoinMulticast(intptr_t fd, 525 bool BaseSocket::JoinMulticast(intptr_t fd,
516 const RawAddr& addr, 526 const RawAddr& addr,
517 const RawAddr&, 527 const RawAddr&,
518 int interfaceIndex) { 528 int interfaceIndex) {
519 LOG_ERR("Socket::JoinMulticast is unimplemented\n"); 529 LOG_ERR("BaseSocket::JoinMulticast is unimplemented\n");
520 UNIMPLEMENTED(); 530 UNIMPLEMENTED();
521 return false; 531 return false;
522 } 532 }
523 533
524 534
525 bool Socket::LeaveMulticast(intptr_t fd, 535 bool BaseSocket::LeaveMulticast(intptr_t fd,
526 const RawAddr& addr, 536 const RawAddr& addr,
527 const RawAddr&, 537 const RawAddr&,
528 int interfaceIndex) { 538 int interfaceIndex) {
529 LOG_ERR("Socket::LeaveMulticast is unimplemented\n"); 539 LOG_ERR("BaseSocket::LeaveMulticast is unimplemented\n");
530 UNIMPLEMENTED(); 540 UNIMPLEMENTED();
531 return false; 541 return false;
532 } 542 }
533 543
534 } // namespace bin 544 } // namespace bin
535 } // namespace dart 545 } // namespace dart
536 546
537 #endif // defined(TARGET_OS_FUCHSIA) 547 #endif // defined(TARGET_OS_FUCHSIA)
538 548
539 #endif // !defined(DART_IO_DISABLED) 549 #endif // !defined(DART_IO_DISABLED)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698