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 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 const int kBufferSize = 1024; | 130 const int kBufferSize = 1024; |
131 char error_message[kBufferSize]; | 131 char error_message[kBufferSize]; |
132 strerror_r(errno, error_message, kBufferSize); | 132 strerror_r(errno, error_message, kBufferSize); |
133 Log::PrintErr("Error getsockname: %s\n", error_message); | 133 Log::PrintErr("Error getsockname: %s\n", error_message); |
134 return 0; | 134 return 0; |
135 } | 135 } |
136 return SocketAddress::GetAddrPort(&raw); | 136 return SocketAddress::GetAddrPort(&raw); |
137 } | 137 } |
138 | 138 |
139 | 139 |
140 bool Socket::GetRemotePeer(intptr_t fd, char *host, intptr_t *port) { | 140 SocketAddress* Socket::GetRemotePeer(intptr_t fd, intptr_t* port) { |
141 ASSERT(fd >= 0); | 141 ASSERT(fd >= 0); |
142 RawAddr raw; | 142 RawAddr raw; |
143 socklen_t size = sizeof(raw); | 143 socklen_t size = sizeof(raw); |
144 if (TEMP_FAILURE_RETRY( | 144 if (TEMP_FAILURE_RETRY( |
145 getpeername(fd, | 145 getpeername(fd, |
146 &raw.addr, | 146 &raw.addr, |
147 &size))) { | 147 &size))) { |
148 const int kBufferSize = 1024; | 148 const int kBufferSize = 1024; |
149 char error_message[kBufferSize]; | 149 char error_message[kBufferSize]; |
150 strerror_r(errno, error_message, kBufferSize); | 150 strerror_r(errno, error_message, kBufferSize); |
151 Log::PrintErr("Error getpeername: %s\n", error_message); | 151 Log::PrintErr("Error getpeername: %s\n", error_message); |
152 return false; | 152 return NULL; |
153 } | |
154 if (TEMP_FAILURE_RETRY(getnameinfo(&raw.addr, | |
155 size, | |
156 host, | |
157 INET6_ADDRSTRLEN, | |
158 NULL, | |
159 0, | |
160 NI_NUMERICHOST)) != 0) { | |
161 const int kBufferSize = 1024; | |
162 char error_message[kBufferSize]; | |
163 strerror_r(errno, error_message, kBufferSize); | |
164 Log::PrintErr("Error getnameinfo: %s\n", error_message); | |
165 return false; | |
166 } | 153 } |
167 *port = SocketAddress::GetAddrPort(&raw); | 154 *port = SocketAddress::GetAddrPort(&raw); |
168 return true; | 155 return new SocketAddress(&raw.addr); |
169 } | 156 } |
170 | 157 |
171 | 158 |
172 void Socket::GetError(intptr_t fd, OSError* os_error) { | 159 void Socket::GetError(intptr_t fd, OSError* os_error) { |
173 int len = sizeof(errno); | 160 int len = sizeof(errno); |
174 getsockopt(fd, | 161 getsockopt(fd, |
175 SOL_SOCKET, | 162 SOL_SOCKET, |
176 SO_ERROR, | 163 SO_ERROR, |
177 &errno, | 164 &errno, |
178 reinterpret_cast<socklen_t*>(&len)); | 165 reinterpret_cast<socklen_t*>(&len)); |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
407 IPPROTO_TCP, | 394 IPPROTO_TCP, |
408 TCP_NODELAY, | 395 TCP_NODELAY, |
409 reinterpret_cast<char *>(&on), | 396 reinterpret_cast<char *>(&on), |
410 sizeof(on))) == 0; | 397 sizeof(on))) == 0; |
411 } | 398 } |
412 | 399 |
413 } // namespace bin | 400 } // namespace bin |
414 } // namespace dart | 401 } // namespace dart |
415 | 402 |
416 #endif // defined(TARGET_OS_MACOS) | 403 #endif // defined(TARGET_OS_MACOS) |
OLD | NEW |