| 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_LINUX) | 6 #if defined(TARGET_OS_LINUX) |
| 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_buf[kBufferSize]; | 131 char error_buf[kBufferSize]; |
| 132 Log::PrintErr("Error getsockname: %s\n", | 132 Log::PrintErr("Error getsockname: %s\n", |
| 133 strerror_r(errno, error_buf, kBufferSize)); | 133 strerror_r(errno, error_buf, kBufferSize)); |
| 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_buf[kBufferSize]; | 149 char error_buf[kBufferSize]; |
| 150 Log::PrintErr("Error getpeername: %s\n", | 150 Log::PrintErr("Error getpeername: %s\n", |
| 151 strerror_r(errno, error_buf, kBufferSize)); | 151 strerror_r(errno, error_buf, kBufferSize)); |
| 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_buf[kBufferSize]; | |
| 163 Log::PrintErr("Error getnameinfo: %s\n", | |
| 164 strerror_r(errno, error_buf, kBufferSize)); | |
| 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 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 416 IPPROTO_TCP, | 403 IPPROTO_TCP, |
| 417 TCP_NODELAY, | 404 TCP_NODELAY, |
| 418 reinterpret_cast<char *>(&on), | 405 reinterpret_cast<char *>(&on), |
| 419 sizeof(on))) == 0; | 406 sizeof(on))) == 0; |
| 420 } | 407 } |
| 421 | 408 |
| 422 } // namespace bin | 409 } // namespace bin |
| 423 } // namespace dart | 410 } // namespace dart |
| 424 | 411 |
| 425 #endif // defined(TARGET_OS_LINUX) | 412 #endif // defined(TARGET_OS_LINUX) |
| OLD | NEW |