| 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 30 matching lines...) Expand all Loading... |
| 41 // Nothing to do on Mac OS. | 41 // Nothing to do on Mac OS. |
| 42 return true; | 42 return true; |
| 43 } | 43 } |
| 44 | 44 |
| 45 | 45 |
| 46 intptr_t Socket::Create(RawAddr addr) { | 46 intptr_t Socket::Create(RawAddr addr) { |
| 47 intptr_t fd; | 47 intptr_t fd; |
| 48 | 48 |
| 49 fd = TEMP_FAILURE_RETRY(socket(addr.ss.ss_family, SOCK_STREAM, 0)); | 49 fd = TEMP_FAILURE_RETRY(socket(addr.ss.ss_family, SOCK_STREAM, 0)); |
| 50 if (fd < 0) { | 50 if (fd < 0) { |
| 51 Log::PrintErr("Error Create: %s\n", strerror(errno)); | 51 const int kBufferSize = 1024; |
| 52 char error_message[kBufferSize]; |
| 53 strerror_r(errno, error_message, kBufferSize); |
| 54 Log::PrintErr("Error Create: %s\n", error_message); |
| 52 return -1; | 55 return -1; |
| 53 } | 56 } |
| 54 | 57 |
| 55 FDUtils::SetCloseOnExec(fd); | 58 FDUtils::SetCloseOnExec(fd); |
| 56 return fd; | 59 return fd; |
| 57 } | 60 } |
| 58 | 61 |
| 59 | 62 |
| 60 intptr_t Socket::Connect(intptr_t fd, RawAddr addr, const intptr_t port) { | 63 intptr_t Socket::Connect(intptr_t fd, RawAddr addr, const intptr_t port) { |
| 61 SocketAddress::SetAddrPort(&addr, port); | 64 SocketAddress::SetAddrPort(&addr, port); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 | 118 |
| 116 | 119 |
| 117 intptr_t Socket::GetPort(intptr_t fd) { | 120 intptr_t Socket::GetPort(intptr_t fd) { |
| 118 ASSERT(fd >= 0); | 121 ASSERT(fd >= 0); |
| 119 RawAddr raw; | 122 RawAddr raw; |
| 120 socklen_t size = sizeof(raw); | 123 socklen_t size = sizeof(raw); |
| 121 if (TEMP_FAILURE_RETRY( | 124 if (TEMP_FAILURE_RETRY( |
| 122 getsockname(fd, | 125 getsockname(fd, |
| 123 &raw.addr, | 126 &raw.addr, |
| 124 &size))) { | 127 &size))) { |
| 125 Log::PrintErr("Error getsockname: %s\n", strerror(errno)); | 128 const int kBufferSize = 1024; |
| 129 char error_message[kBufferSize]; |
| 130 strerror_r(errno, error_message, kBufferSize); |
| 131 Log::PrintErr("Error getsockname: %s\n", error_message); |
| 126 return 0; | 132 return 0; |
| 127 } | 133 } |
| 128 return SocketAddress::GetAddrPort(&raw); | 134 return SocketAddress::GetAddrPort(&raw); |
| 129 } | 135 } |
| 130 | 136 |
| 131 | 137 |
| 132 bool Socket::GetRemotePeer(intptr_t fd, char *host, intptr_t *port) { | 138 bool Socket::GetRemotePeer(intptr_t fd, char *host, intptr_t *port) { |
| 133 ASSERT(fd >= 0); | 139 ASSERT(fd >= 0); |
| 134 RawAddr raw; | 140 RawAddr raw; |
| 135 socklen_t size = sizeof(raw); | 141 socklen_t size = sizeof(raw); |
| 136 if (TEMP_FAILURE_RETRY( | 142 if (TEMP_FAILURE_RETRY( |
| 137 getpeername(fd, | 143 getpeername(fd, |
| 138 &raw.addr, | 144 &raw.addr, |
| 139 &size))) { | 145 &size))) { |
| 140 Log::PrintErr("Error getpeername: %s\n", strerror(errno)); | 146 const int kBufferSize = 1024; |
| 147 char error_message[kBufferSize]; |
| 148 strerror_r(errno, error_message, kBufferSize); |
| 149 Log::PrintErr("Error getpeername: %s\n", error_message); |
| 141 return false; | 150 return false; |
| 142 } | 151 } |
| 143 const void* src; | 152 const void* src; |
| 144 if (raw.ss.ss_family == AF_INET6) { | 153 if (raw.ss.ss_family == AF_INET6) { |
| 145 src = reinterpret_cast<const void*>(&raw.in6.sin6_addr); | 154 src = reinterpret_cast<const void*>(&raw.in6.sin6_addr); |
| 146 } else { | 155 } else { |
| 147 src = reinterpret_cast<const void*>(&raw.in.sin_addr); | 156 src = reinterpret_cast<const void*>(&raw.in.sin_addr); |
| 148 } | 157 } |
| 149 if (inet_ntop(raw.ss.ss_family, | 158 if (inet_ntop(raw.ss.ss_family, |
| 150 src, | 159 src, |
| 151 host, | 160 host, |
| 152 INET_ADDRSTRLEN) == NULL) { | 161 INET_ADDRSTRLEN) == NULL) { |
| 153 Log::PrintErr("Error inet_ntop: %s\n", strerror(errno)); | 162 const int kBufferSize = 1024; |
| 163 char error_message[kBufferSize]; |
| 164 strerror_r(errno, error_message, kBufferSize); |
| 165 Log::PrintErr("Error inet_ntop: %s\n", error_message); |
| 154 return false; | 166 return false; |
| 155 } | 167 } |
| 156 *port = SocketAddress::GetAddrPort(&raw); | 168 *port = SocketAddress::GetAddrPort(&raw); |
| 157 return true; | 169 return true; |
| 158 } | 170 } |
| 159 | 171 |
| 160 | 172 |
| 161 void Socket::GetError(intptr_t fd, OSError* os_error) { | 173 void Socket::GetError(intptr_t fd, OSError* os_error) { |
| 162 int len = sizeof(errno); | 174 int len = sizeof(errno); |
| 163 getsockopt(fd, | 175 getsockopt(fd, |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 395 IPPROTO_TCP, | 407 IPPROTO_TCP, |
| 396 TCP_NODELAY, | 408 TCP_NODELAY, |
| 397 reinterpret_cast<char *>(&on), | 409 reinterpret_cast<char *>(&on), |
| 398 sizeof(on))) == 0; | 410 sizeof(on))) == 0; |
| 399 } | 411 } |
| 400 | 412 |
| 401 } // namespace bin | 413 } // namespace bin |
| 402 } // namespace dart | 414 } // namespace dart |
| 403 | 415 |
| 404 #endif // defined(TARGET_OS_MACOS) | 416 #endif // defined(TARGET_OS_MACOS) |
| OLD | NEW |