| 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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 return true; | 48 return true; |
| 49 } | 49 } |
| 50 | 50 |
| 51 | 51 |
| 52 bool Socket::Initialize() { | 52 bool Socket::Initialize() { |
| 53 // Nothing to do on Android. | 53 // Nothing to do on Android. |
| 54 return true; | 54 return true; |
| 55 } | 55 } |
| 56 | 56 |
| 57 | 57 |
| 58 intptr_t Socket::Create(RawAddr addr) { | 58 static intptr_t Create(RawAddr addr) { |
| 59 intptr_t fd; | 59 intptr_t fd; |
| 60 fd = NO_RETRY_EXPECTED(socket(addr.ss.ss_family, SOCK_STREAM, 0)); | 60 fd = NO_RETRY_EXPECTED(socket(addr.ss.ss_family, SOCK_STREAM, 0)); |
| 61 if (fd < 0) { | 61 if (fd < 0) { |
| 62 return -1; | 62 return -1; |
| 63 } | 63 } |
| 64 FDUtils::SetCloseOnExec(fd); | 64 FDUtils::SetCloseOnExec(fd); |
| 65 return fd; | 65 return fd; |
| 66 } | 66 } |
| 67 | 67 |
| 68 | 68 |
| 69 intptr_t Socket::Connect(intptr_t fd, RawAddr addr, const intptr_t port) { | 69 static intptr_t Connect(intptr_t fd, RawAddr addr, const intptr_t port) { |
| 70 SocketAddress::SetAddrPort(&addr, port); | 70 SocketAddress::SetAddrPort(&addr, port); |
| 71 intptr_t result = TEMP_FAILURE_RETRY( | 71 intptr_t result = TEMP_FAILURE_RETRY( |
| 72 connect(fd, &addr.addr, SocketAddress::GetAddrLength(&addr))); | 72 connect(fd, &addr.addr, SocketAddress::GetAddrLength(&addr))); |
| 73 if (result == 0 || errno == EINPROGRESS) { | 73 if (result == 0 || errno == EINPROGRESS) { |
| 74 return fd; | 74 return fd; |
| 75 } | 75 } |
| 76 VOID_TEMP_FAILURE_RETRY(close(fd)); | 76 VOID_TEMP_FAILURE_RETRY(close(fd)); |
| 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(const RawAddr& addr, const intptr_t port) { |
| 82 intptr_t fd = Socket::Create(addr); | 82 intptr_t fd = Create(addr); |
| 83 if (fd < 0) { | 83 if (fd < 0) { |
| 84 return fd; | 84 return fd; |
| 85 } | 85 } |
| 86 | 86 |
| 87 FDUtils::SetNonBlocking(fd); | 87 FDUtils::SetNonBlocking(fd); |
| 88 | 88 |
| 89 return Socket::Connect(fd, addr, port); | 89 return Connect(fd, addr, port); |
| 90 } | 90 } |
| 91 | 91 |
| 92 | 92 |
| 93 intptr_t Socket::CreateBindConnect(const RawAddr& addr, |
| 94 const intptr_t port, |
| 95 const RawAddr& source_addr) { |
| 96 intptr_t fd = Create(addr); |
| 97 if (fd < 0) { |
| 98 return fd; |
| 99 } |
| 100 |
| 101 intptr_t result = TEMP_FAILURE_RETRY( |
| 102 bind(fd, &source_addr.addr, SocketAddress::GetAddrLength(&source_addr))); |
| 103 if (result != 0 && errno != EINPROGRESS) { |
| 104 VOID_TEMP_FAILURE_RETRY(close(fd)); |
| 105 return -1; |
| 106 } |
| 107 |
| 108 return Connect(fd, addr, port); |
| 109 } |
| 110 |
| 111 |
| 93 intptr_t Socket::Available(intptr_t fd) { | 112 intptr_t Socket::Available(intptr_t fd) { |
| 94 return FDUtils::AvailableBytes(fd); | 113 return FDUtils::AvailableBytes(fd); |
| 95 } | 114 } |
| 96 | 115 |
| 97 | 116 |
| 98 intptr_t Socket::Read(intptr_t fd, void* buffer, intptr_t num_bytes) { | 117 intptr_t Socket::Read(intptr_t fd, void* buffer, intptr_t num_bytes) { |
| 99 ASSERT(fd >= 0); | 118 ASSERT(fd >= 0); |
| 100 ssize_t read_bytes = TEMP_FAILURE_RETRY(read(fd, buffer, num_bytes)); | 119 ssize_t read_bytes = TEMP_FAILURE_RETRY(read(fd, buffer, num_bytes)); |
| 101 ASSERT(EAGAIN == EWOULDBLOCK); | 120 ASSERT(EAGAIN == EWOULDBLOCK); |
| 102 if (read_bytes == -1 && errno == EWOULDBLOCK) { | 121 if (read_bytes == -1 && errno == EWOULDBLOCK) { |
| (...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 542 mreq.gr_interface = interfaceIndex; | 561 mreq.gr_interface = interfaceIndex; |
| 543 memmove(&mreq.gr_group, &addr->ss, SocketAddress::GetAddrLength(addr)); | 562 memmove(&mreq.gr_group, &addr->ss, SocketAddress::GetAddrLength(addr)); |
| 544 return NO_RETRY_EXPECTED(setsockopt( | 563 return NO_RETRY_EXPECTED(setsockopt( |
| 545 fd, proto, MCAST_LEAVE_GROUP, &mreq, sizeof(mreq))) == 0; | 564 fd, proto, MCAST_LEAVE_GROUP, &mreq, sizeof(mreq))) == 0; |
| 546 } | 565 } |
| 547 | 566 |
| 548 } // namespace bin | 567 } // namespace bin |
| 549 } // namespace dart | 568 } // namespace dart |
| 550 | 569 |
| 551 #endif // defined(TARGET_OS_ANDROID) | 570 #endif // defined(TARGET_OS_ANDROID) |
| OLD | NEW |