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> | |
6 #include <errno.h> | 5 #include <errno.h> |
7 #include <netdb.h> | |
8 #include <stdio.h> | 6 #include <stdio.h> |
9 #include <stdlib.h> | 7 #include <stdlib.h> |
10 #include <string.h> | 8 #include <string.h> |
11 #include <sys/socket.h> | |
12 #include <unistd.h> | 9 #include <unistd.h> |
13 | 10 |
14 #include "bin/fdutils.h" | 11 #include "bin/fdutils.h" |
15 #include "bin/socket.h" | 12 #include "bin/socket.h" |
16 | 13 |
17 | 14 |
18 bool Socket::Initialize() { | 15 bool Socket::Initialize() { |
19 // Nothing to do on Linux. | 16 // Nothing to do on Linux. |
20 return true; | 17 return true; |
21 } | 18 } |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 reinterpret_cast<struct sockaddr *>(&socket_address), | 93 reinterpret_cast<struct sockaddr *>(&socket_address), |
97 &size))) { | 94 &size))) { |
98 fprintf(stderr, "Error getsockname: %s\n", strerror(errno)); | 95 fprintf(stderr, "Error getsockname: %s\n", strerror(errno)); |
99 return 0; | 96 return 0; |
100 } | 97 } |
101 return ntohs(socket_address.sin_port); | 98 return ntohs(socket_address.sin_port); |
102 } | 99 } |
103 | 100 |
104 | 101 |
105 bool Socket::GetRemotePeer(intptr_t fd, char *host, intptr_t *port) { | 102 bool Socket::GetRemotePeer(intptr_t fd, char *host, intptr_t *port) { |
106 ASSERT(DART_INET_ADDRSTRLEN >= INET_ADDRSTRLEN); | |
107 ASSERT(fd >= 0); | 103 ASSERT(fd >= 0); |
108 struct sockaddr_in socket_address; | 104 struct sockaddr_in socket_address; |
109 socklen_t size = sizeof(socket_address); | 105 socklen_t size = sizeof(socket_address); |
110 if (TEMP_FAILURE_RETRY( | 106 if (TEMP_FAILURE_RETRY( |
111 getpeername(fd, | 107 getpeername(fd, |
112 reinterpret_cast<struct sockaddr *>(&socket_address), | 108 reinterpret_cast<struct sockaddr *>(&socket_address), |
113 &size))) { | 109 &size))) { |
114 fprintf(stderr, "Error getpeername: %s\n", strerror(errno)); | 110 fprintf(stderr, "Error getpeername: %s\n", strerror(errno)); |
115 return false; | 111 return false; |
116 } | 112 } |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 // error. We got woken up from the poll on the listening socket, | 231 // error. We got woken up from the poll on the listening socket, |
236 // but there is no connection ready to be accepted. | 232 // but there is no connection ready to be accepted. |
237 ASSERT(kTemporaryFailure != -1); | 233 ASSERT(kTemporaryFailure != -1); |
238 socket = kTemporaryFailure; | 234 socket = kTemporaryFailure; |
239 } | 235 } |
240 } else { | 236 } else { |
241 FDUtils::SetNonBlocking(socket); | 237 FDUtils::SetNonBlocking(socket); |
242 } | 238 } |
243 return socket; | 239 return socket; |
244 } | 240 } |
OLD | NEW |