| 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 <arpa/inet.h> | 5 #include <arpa/inet.h> |
| 6 #include <errno.h> | 6 #include <errno.h> |
| 7 #include <netdb.h> | 7 #include <netdb.h> |
| 8 #include <stdio.h> | 8 #include <stdio.h> |
| 9 #include <stdlib.h> | 9 #include <stdlib.h> |
| 10 #include <string.h> | 10 #include <string.h> |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 | 88 |
| 89 | 89 |
| 90 intptr_t Socket::GetPort(intptr_t fd) { | 90 intptr_t Socket::GetPort(intptr_t fd) { |
| 91 ASSERT(fd >= 0); | 91 ASSERT(fd >= 0); |
| 92 struct sockaddr_in socket_address; | 92 struct sockaddr_in socket_address; |
| 93 socklen_t size = sizeof(socket_address); | 93 socklen_t size = sizeof(socket_address); |
| 94 if (TEMP_FAILURE_RETRY( | 94 if (TEMP_FAILURE_RETRY( |
| 95 getsockname(fd, | 95 getsockname(fd, |
| 96 reinterpret_cast<struct sockaddr *>(&socket_address), | 96 reinterpret_cast<struct sockaddr *>(&socket_address), |
| 97 &size))) { | 97 &size))) { |
| 98 fprintf(stderr, "Error getsockname: %s\n", strerror(errno)); |
| 99 return 0; |
| 100 } |
| 101 return ntohs(socket_address.sin_port); |
| 102 } |
| 103 |
| 104 |
| 105 intptr_t Socket::GetRemotePort(intptr_t fd) { |
| 106 ASSERT(fd >= 0); |
| 107 struct sockaddr_in socket_address; |
| 108 socklen_t size = sizeof(socket_address); |
| 109 if (TEMP_FAILURE_RETRY( |
| 110 getpeername(fd, |
| 111 reinterpret_cast<struct sockaddr *>(&socket_address), |
| 112 &size))) { |
| 113 fprintf(stderr, "Error getpeername: %s\n", strerror(errno)); |
| 98 return 0; | 114 return 0; |
| 99 } | 115 } |
| 100 return ntohs(socket_address.sin_port); | 116 return ntohs(socket_address.sin_port); |
| 101 } | 117 } |
| 102 | 118 |
| 103 | 119 |
| 104 void Socket::GetError(intptr_t fd, OSError* os_error) { | 120 void Socket::GetError(intptr_t fd, OSError* os_error) { |
| 105 int len = sizeof(errno); | 121 int len = sizeof(errno); |
| 106 getsockopt(fd, | 122 getsockopt(fd, |
| 107 SOL_SOCKET, | 123 SOL_SOCKET, |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 // error. We got woken up from the poll on the listening socket, | 226 // error. We got woken up from the poll on the listening socket, |
| 211 // but there is no connection ready to be accepted. | 227 // but there is no connection ready to be accepted. |
| 212 ASSERT(kTemporaryFailure != -1); | 228 ASSERT(kTemporaryFailure != -1); |
| 213 socket = kTemporaryFailure; | 229 socket = kTemporaryFailure; |
| 214 } | 230 } |
| 215 } else { | 231 } else { |
| 216 FDUtils::SetNonBlocking(socket); | 232 FDUtils::SetNonBlocking(socket); |
| 217 } | 233 } |
| 218 return socket; | 234 return socket; |
| 219 } | 235 } |
| OLD | NEW |