| 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 24 matching lines...) Expand all Loading... |
| 35 addrinfo->ai_addrlen); | 35 addrinfo->ai_addrlen); |
| 36 } | 36 } |
| 37 | 37 |
| 38 | 38 |
| 39 bool Socket::Initialize() { | 39 bool Socket::Initialize() { |
| 40 // Nothing to do on Mac OS. | 40 // Nothing to do on Mac OS. |
| 41 return true; | 41 return true; |
| 42 } | 42 } |
| 43 | 43 |
| 44 | 44 |
| 45 intptr_t Socket::CreateConnect(RawAddr addr, const intptr_t port) { | 45 intptr_t Socket::Create(RawAddr addr) { |
| 46 intptr_t fd; | 46 intptr_t fd; |
| 47 | 47 |
| 48 fd = TEMP_FAILURE_RETRY(socket(addr.ss.ss_family, SOCK_STREAM, 0)); | 48 fd = TEMP_FAILURE_RETRY(socket(addr.ss.ss_family, SOCK_STREAM, 0)); |
| 49 if (fd < 0) { | 49 if (fd < 0) { |
| 50 Log::PrintErr("Error CreateConnect: %s\n", strerror(errno)); | 50 Log::PrintErr("Error Create: %s\n", strerror(errno)); |
| 51 return -1; | 51 return -1; |
| 52 } | 52 } |
| 53 | 53 |
| 54 FDUtils::SetCloseOnExec(fd); | 54 FDUtils::SetCloseOnExec(fd); |
| 55 Socket::SetNonBlocking(fd); | 55 return fd; |
| 56 } |
| 56 | 57 |
| 58 |
| 59 intptr_t Socket::Connect(intptr_t fd, RawAddr addr, const intptr_t port) { |
| 57 SocketAddress::SetAddrPort(&addr, port); | 60 SocketAddress::SetAddrPort(&addr, port); |
| 58 intptr_t result = TEMP_FAILURE_RETRY( | 61 intptr_t result = TEMP_FAILURE_RETRY( |
| 59 connect(fd, | 62 connect(fd, |
| 60 &addr.addr, | 63 &addr.addr, |
| 61 SocketAddress::GetAddrLength(addr))); | 64 SocketAddress::GetAddrLength(addr))); |
| 62 if (result == 0 || errno == EINPROGRESS) { | 65 if (result == 0 || errno == EINPROGRESS) { |
| 63 return fd; | 66 return fd; |
| 64 } | 67 } |
| 65 VOID_TEMP_FAILURE_RETRY(close(fd)); | 68 VOID_TEMP_FAILURE_RETRY(close(fd)); |
| 66 return -1; | 69 return -1; |
| 67 } | 70 } |
| 68 | 71 |
| 69 | 72 |
| 73 intptr_t Socket::CreateConnect(RawAddr addr, const intptr_t port) { |
| 74 intptr_t fd = Socket::Create(addr); |
| 75 if (fd < 0) { |
| 76 return fd; |
| 77 } |
| 78 |
| 79 Socket::SetNonBlocking(fd); |
| 80 |
| 81 return Socket::Connect(fd, addr, port); |
| 82 } |
| 83 |
| 84 |
| 70 intptr_t Socket::Available(intptr_t fd) { | 85 intptr_t Socket::Available(intptr_t fd) { |
| 71 return FDUtils::AvailableBytes(fd); | 86 return FDUtils::AvailableBytes(fd); |
| 72 } | 87 } |
| 73 | 88 |
| 74 | 89 |
| 75 int Socket::Read(intptr_t fd, void* buffer, intptr_t num_bytes) { | 90 int Socket::Read(intptr_t fd, void* buffer, intptr_t num_bytes) { |
| 76 ASSERT(fd >= 0); | 91 ASSERT(fd >= 0); |
| 77 ssize_t read_bytes = TEMP_FAILURE_RETRY(read(fd, buffer, num_bytes)); | 92 ssize_t read_bytes = TEMP_FAILURE_RETRY(read(fd, buffer, num_bytes)); |
| 78 ASSERT(EAGAIN == EWOULDBLOCK); | 93 ASSERT(EAGAIN == EWOULDBLOCK); |
| 79 if (read_bytes == -1 && errno == EWOULDBLOCK) { | 94 if (read_bytes == -1 && errno == EWOULDBLOCK) { |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 293 IPPROTO_TCP, | 308 IPPROTO_TCP, |
| 294 TCP_NODELAY, | 309 TCP_NODELAY, |
| 295 reinterpret_cast<char *>(&on), | 310 reinterpret_cast<char *>(&on), |
| 296 sizeof(on))) == 0; | 311 sizeof(on))) == 0; |
| 297 } | 312 } |
| 298 | 313 |
| 299 } // namespace bin | 314 } // namespace bin |
| 300 } // namespace dart | 315 } // namespace dart |
| 301 | 316 |
| 302 #endif // defined(TARGET_OS_MACOS) | 317 #endif // defined(TARGET_OS_MACOS) |
| OLD | NEW |