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

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

Issue 9963053: Add remotePort getter to Socket. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: 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_linux.cc ('k') | runtime/bin/socket_win.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) {
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));
114 return 0;
115 }
116 return ntohs(socket_address.sin_port);
117 }
118
119
105 void Socket::GetError(intptr_t fd, OSError* os_error) { 120 void Socket::GetError(intptr_t fd, OSError* os_error) {
106 int len = sizeof(errno); 121 int len = sizeof(errno);
107 getsockopt(fd, 122 getsockopt(fd,
108 SOL_SOCKET, 123 SOL_SOCKET,
109 SO_ERROR, 124 SO_ERROR,
110 &errno, 125 &errno,
111 reinterpret_cast<socklen_t*>(&len)); 126 reinterpret_cast<socklen_t*>(&len));
112 os_error->SetCodeAndMessage(OSError::kSystem, errno); 127 os_error->SetCodeAndMessage(OSError::kSystem, errno);
113 } 128 }
114 129
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 // error. We got woken up from the poll on the listening socket, 216 // error. We got woken up from the poll on the listening socket,
202 // but there is no connection ready to be accepted. 217 // but there is no connection ready to be accepted.
203 ASSERT(kTemporaryFailure != -1); 218 ASSERT(kTemporaryFailure != -1);
204 socket = kTemporaryFailure; 219 socket = kTemporaryFailure;
205 } 220 }
206 } else { 221 } else {
207 FDUtils::SetNonBlocking(socket); 222 FDUtils::SetNonBlocking(socket);
208 } 223 }
209 return socket; 224 return socket;
210 } 225 }
OLDNEW
« no previous file with comments | « runtime/bin/socket_linux.cc ('k') | runtime/bin/socket_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698