Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(42)

Side by Side Diff: runtime/bin/socket_linux.cc

Issue 10032027: Add remoteHost to Socket. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Removed then need for allocating buffer in heap. Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/bin/socket_impl.dart ('k') | runtime/bin/socket_macos.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
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)); 98 fprintf(stderr, "Error getsockname: %s\n", strerror(errno));
99 return 0; 99 return 0;
100 } 100 }
101 return ntohs(socket_address.sin_port); 101 return ntohs(socket_address.sin_port);
102 } 102 }
103 103
104 104
105 intptr_t Socket::GetRemotePort(intptr_t fd) { 105 bool Socket::GetRemotePeer(intptr_t fd, char *host, intptr_t *port) {
106 ASSERT(DART_INET_ADDRSTRLEN >= INET_ADDRSTRLEN);
106 ASSERT(fd >= 0); 107 ASSERT(fd >= 0);
107 struct sockaddr_in socket_address; 108 struct sockaddr_in socket_address;
108 socklen_t size = sizeof(socket_address); 109 socklen_t size = sizeof(socket_address);
109 if (TEMP_FAILURE_RETRY( 110 if (TEMP_FAILURE_RETRY(
110 getpeername(fd, 111 getpeername(fd,
111 reinterpret_cast<struct sockaddr *>(&socket_address), 112 reinterpret_cast<struct sockaddr *>(&socket_address),
112 &size))) { 113 &size))) {
113 fprintf(stderr, "Error getpeername: %s\n", strerror(errno)); 114 fprintf(stderr, "Error getpeername: %s\n", strerror(errno));
114 return 0; 115 return false;
115 } 116 }
116 return ntohs(socket_address.sin_port); 117 if (inet_ntop(socket_address.sin_family,
118 reinterpret_cast<const void *>(&socket_address.sin_addr),
119 host,
120 INET_ADDRSTRLEN) == NULL) {
121 fprintf(stderr, "Error inet_ntop: %s\n", strerror(errno));
122 return false;
123 }
124 *port = ntohs(socket_address.sin_port);
125 return true;
117 } 126 }
118 127
119 128
120 void Socket::GetError(intptr_t fd, OSError* os_error) { 129 void Socket::GetError(intptr_t fd, OSError* os_error) {
121 int len = sizeof(errno); 130 int len = sizeof(errno);
122 getsockopt(fd, 131 getsockopt(fd,
123 SOL_SOCKET, 132 SOL_SOCKET,
124 SO_ERROR, 133 SO_ERROR,
125 &errno, 134 &errno,
126 reinterpret_cast<socklen_t*>(&len)); 135 reinterpret_cast<socklen_t*>(&len));
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 // error. We got woken up from the poll on the listening socket, 235 // error. We got woken up from the poll on the listening socket,
227 // but there is no connection ready to be accepted. 236 // but there is no connection ready to be accepted.
228 ASSERT(kTemporaryFailure != -1); 237 ASSERT(kTemporaryFailure != -1);
229 socket = kTemporaryFailure; 238 socket = kTemporaryFailure;
230 } 239 }
231 } else { 240 } else {
232 FDUtils::SetNonBlocking(socket); 241 FDUtils::SetNonBlocking(socket);
233 } 242 }
234 return socket; 243 return socket;
235 } 244 }
OLDNEW
« no previous file with comments | « runtime/bin/socket_impl.dart ('k') | runtime/bin/socket_macos.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698