| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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_ANDROID) | 6 #if defined(TARGET_OS_ANDROID) |
| 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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 return -1; | 77 return -1; |
| 78 } | 78 } |
| 79 | 79 |
| 80 | 80 |
| 81 intptr_t Socket::CreateConnect(RawAddr addr, const intptr_t port) { | 81 intptr_t Socket::CreateConnect(RawAddr addr, const intptr_t port) { |
| 82 intptr_t fd = Socket::Create(addr); | 82 intptr_t fd = Socket::Create(addr); |
| 83 if (fd < 0) { | 83 if (fd < 0) { |
| 84 return fd; | 84 return fd; |
| 85 } | 85 } |
| 86 | 86 |
| 87 Socket::SetNonBlocking(fd); | 87 FDUtils::SetNonBlocking(fd); |
| 88 | 88 |
| 89 return Socket::Connect(fd, addr, port); | 89 return Socket::Connect(fd, addr, port); |
| 90 } | 90 } |
| 91 | 91 |
| 92 | 92 |
| 93 intptr_t Socket::Available(intptr_t fd) { | 93 intptr_t Socket::Available(intptr_t fd) { |
| 94 return FDUtils::AvailableBytes(fd); | 94 return FDUtils::AvailableBytes(fd); |
| 95 } | 95 } |
| 96 | 96 |
| 97 | 97 |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 | 298 |
| 299 SocketAddress::SetAddrPort(addr, port); | 299 SocketAddress::SetAddrPort(addr, port); |
| 300 if (NO_RETRY_EXPECTED( | 300 if (NO_RETRY_EXPECTED( |
| 301 bind(fd, | 301 bind(fd, |
| 302 &addr->addr, | 302 &addr->addr, |
| 303 SocketAddress::GetAddrLength(addr))) < 0) { | 303 SocketAddress::GetAddrLength(addr))) < 0) { |
| 304 VOID_TEMP_FAILURE_RETRY(close(fd)); | 304 VOID_TEMP_FAILURE_RETRY(close(fd)); |
| 305 return -1; | 305 return -1; |
| 306 } | 306 } |
| 307 | 307 |
| 308 Socket::SetNonBlocking(fd); | 308 FDUtils::SetNonBlocking(fd); |
| 309 return fd; | 309 return fd; |
| 310 } | 310 } |
| 311 | 311 |
| 312 | 312 |
| 313 AddressList<InterfaceSocketAddress>* Socket::ListInterfaces( | 313 AddressList<InterfaceSocketAddress>* Socket::ListInterfaces( |
| 314 int type, | 314 int type, |
| 315 OSError** os_error) { | 315 OSError** os_error) { |
| 316 // The ifaddrs.h header is not provided on Android. An Android | 316 // The ifaddrs.h header is not provided on Android. An Android |
| 317 // implementation would have to use IOCTL or netlink. | 317 // implementation would have to use IOCTL or netlink. |
| 318 return NULL; | 318 return NULL; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 VOID_TEMP_FAILURE_RETRY(close(fd)); | 358 VOID_TEMP_FAILURE_RETRY(close(fd)); |
| 359 errno = err; | 359 errno = err; |
| 360 return new_fd; | 360 return new_fd; |
| 361 } | 361 } |
| 362 | 362 |
| 363 if (NO_RETRY_EXPECTED(listen(fd, backlog > 0 ? backlog : SOMAXCONN)) != 0) { | 363 if (NO_RETRY_EXPECTED(listen(fd, backlog > 0 ? backlog : SOMAXCONN)) != 0) { |
| 364 VOID_TEMP_FAILURE_RETRY(close(fd)); | 364 VOID_TEMP_FAILURE_RETRY(close(fd)); |
| 365 return -1; | 365 return -1; |
| 366 } | 366 } |
| 367 | 367 |
| 368 Socket::SetNonBlocking(fd); | 368 FDUtils::SetNonBlocking(fd); |
| 369 return fd; | 369 return fd; |
| 370 } | 370 } |
| 371 | 371 |
| 372 | 372 |
| 373 bool ServerSocket::StartAccept(intptr_t fd) { | 373 bool ServerSocket::StartAccept(intptr_t fd) { |
| 374 USE(fd); | 374 USE(fd); |
| 375 return true; | 375 return true; |
| 376 } | 376 } |
| 377 | 377 |
| 378 | 378 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 393 socket = TEMP_FAILURE_RETRY(accept(fd, &clientaddr, &addrlen)); | 393 socket = TEMP_FAILURE_RETRY(accept(fd, &clientaddr, &addrlen)); |
| 394 if (socket == -1) { | 394 if (socket == -1) { |
| 395 if (IsTemporaryAcceptError(errno)) { | 395 if (IsTemporaryAcceptError(errno)) { |
| 396 // We need to signal to the caller that this is actually not an | 396 // We need to signal to the caller that this is actually not an |
| 397 // error. We got woken up from the poll on the listening socket, | 397 // error. We got woken up from the poll on the listening socket, |
| 398 // but there is no connection ready to be accepted. | 398 // but there is no connection ready to be accepted. |
| 399 ASSERT(kTemporaryFailure != -1); | 399 ASSERT(kTemporaryFailure != -1); |
| 400 socket = kTemporaryFailure; | 400 socket = kTemporaryFailure; |
| 401 } | 401 } |
| 402 } else { | 402 } else { |
| 403 Socket::SetNonBlocking(socket); | 403 FDUtils::SetCloseOnExec(socket); |
| 404 FDUtils::SetNonBlocking(socket); |
| 404 } | 405 } |
| 405 return socket; | 406 return socket; |
| 406 } | 407 } |
| 407 | 408 |
| 408 | 409 |
| 409 void Socket::Close(intptr_t fd) { | 410 void Socket::Close(intptr_t fd) { |
| 410 ASSERT(fd >= 0); | 411 ASSERT(fd >= 0); |
| 411 VOID_TEMP_FAILURE_RETRY(close(fd)); | 412 VOID_TEMP_FAILURE_RETRY(close(fd)); |
| 412 } | 413 } |
| 413 | 414 |
| 414 | 415 |
| 415 bool Socket::SetNonBlocking(intptr_t fd) { | |
| 416 return FDUtils::SetNonBlocking(fd); | |
| 417 } | |
| 418 | |
| 419 | |
| 420 bool Socket::SetBlocking(intptr_t fd) { | |
| 421 return FDUtils::SetBlocking(fd); | |
| 422 } | |
| 423 | |
| 424 | |
| 425 bool Socket::GetNoDelay(intptr_t fd, bool* enabled) { | 416 bool Socket::GetNoDelay(intptr_t fd, bool* enabled) { |
| 426 int on; | 417 int on; |
| 427 socklen_t len = sizeof(on); | 418 socklen_t len = sizeof(on); |
| 428 int err = NO_RETRY_EXPECTED(getsockopt(fd, | 419 int err = NO_RETRY_EXPECTED(getsockopt(fd, |
| 429 IPPROTO_TCP, | 420 IPPROTO_TCP, |
| 430 TCP_NODELAY, | 421 TCP_NODELAY, |
| 431 reinterpret_cast<void *>(&on), | 422 reinterpret_cast<void *>(&on), |
| 432 &len)); | 423 &len)); |
| 433 if (err == 0) { | 424 if (err == 0) { |
| 434 *enabled = on == 1; | 425 *enabled = on == 1; |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 551 mreq.gr_interface = interfaceIndex; | 542 mreq.gr_interface = interfaceIndex; |
| 552 memmove(&mreq.gr_group, &addr->ss, SocketAddress::GetAddrLength(addr)); | 543 memmove(&mreq.gr_group, &addr->ss, SocketAddress::GetAddrLength(addr)); |
| 553 return NO_RETRY_EXPECTED(setsockopt( | 544 return NO_RETRY_EXPECTED(setsockopt( |
| 554 fd, proto, MCAST_LEAVE_GROUP, &mreq, sizeof(mreq))) == 0; | 545 fd, proto, MCAST_LEAVE_GROUP, &mreq, sizeof(mreq))) == 0; |
| 555 } | 546 } |
| 556 | 547 |
| 557 } // namespace bin | 548 } // namespace bin |
| 558 } // namespace dart | 549 } // namespace dart |
| 559 | 550 |
| 560 #endif // defined(TARGET_OS_ANDROID) | 551 #endif // defined(TARGET_OS_ANDROID) |
| OLD | NEW |