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

Side by Side Diff: runtime/bin/socket_patch.dart

Issue 14619008: Add static getters for common internet addresses (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed review comments Created 7 years, 7 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.cc ('k') | sdk/lib/_internal/compiler/implementation/lib/io_patch.dart » ('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) 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 patch class RawServerSocket { 5 patch class RawServerSocket {
6 /* patch */ static Future<RawServerSocket> bind([address = "127.0.0.1", 6 /* patch */ static Future<RawServerSocket> bind([address = "127.0.0.1",
7 int port = 0, 7 int port = 0,
8 int backlog = 0]) { 8 int backlog = 0]) {
9 return _RawServerSocket.bind(address, port, backlog); 9 return _RawServerSocket.bind(address, port, backlog);
10 } 10 }
11 } 11 }
12 12
13 13
14 patch class RawSocket { 14 patch class RawSocket {
15 /* patch */ static Future<RawSocket> connect(host, int port) { 15 /* patch */ static Future<RawSocket> connect(host, int port) {
16 return _RawSocket.connect(host, port); 16 return _RawSocket.connect(host, port);
17 } 17 }
18 } 18 }
19 19
20 20
21 patch class InternetAddress { 21 patch class InternetAddress {
22 /* patch */ static InternetAddress get LOOPBACK_IP_V4 {
23 return _InternetAddress.LOOPBACK_IP_V4;
24 }
25
26 /* patch */ static InternetAddress get LOOPBACK_IP_V6 {
27 return _InternetAddress.LOOPBACK_IP_V6;
28 }
29
30 /* patch */ static InternetAddress get ANY_IP_V4 {
31 return _InternetAddress.ANY_IP_V4;
32 }
33
34 /* patch */ static InternetAddress get ANY_IP_V6 {
35 return _InternetAddress.ANY_IP_V6;
36 }
37
22 /* patch */ static Future<List<InternetAddress>> lookup( 38 /* patch */ static Future<List<InternetAddress>> lookup(
23 String host, {InternetAddressType type: InternetAddressType.IPv4}) { 39 String host, {InternetAddressType type: InternetAddressType.IP_V4}) {
24 return _NativeSocket.lookup(host, type: type); 40 return _NativeSocket.lookup(host, type: type);
25 } 41 }
26 } 42 }
27 43
28 class _InternetAddress implements InternetAddress { 44 class _InternetAddress implements InternetAddress {
45 static const int _ADDRESS_LOOPBACK_IP_V4 = 0;
46 static const int _ADDRESS_LOOPBACK_IP_V6 = 1;
47 static const int _ADDRESS_ANY_IP_V4 = 2;
48 static const int _ADDRESS_ANY_IP_V6 = 3;
49
50 static _InternetAddress LOOPBACK_IP_V4 =
51 new _InternetAddress.fixed(_ADDRESS_LOOPBACK_IP_V4);
52 static _InternetAddress LOOPBACK_IP_V6 =
53 new _InternetAddress.fixed(_ADDRESS_LOOPBACK_IP_V6);
54 static _InternetAddress ANY_IP_V4 =
55 new _InternetAddress.fixed(_ADDRESS_ANY_IP_V4);
56 static _InternetAddress ANY_IP_V6 =
57 new _InternetAddress.fixed(_ADDRESS_ANY_IP_V6);
58
29 final InternetAddressType type; 59 final InternetAddressType type;
30 final String address; 60 final String address;
31 final String host; 61 final String host;
32 final Uint8List _sockaddr_storage; 62 final Uint8List _sockaddr_storage;
33 63
34 _InternetAddress(InternetAddressType this.type, 64 _InternetAddress(InternetAddressType this.type,
35 String this.address, 65 String this.address,
36 String this.host, 66 String this.host,
37 List<int> this._sockaddr_storage); 67 List<int> this._sockaddr_storage);
38 68
69 factory _InternetAddress.fixed(int id) {
70 var sockaddr = _fixed(id);
71 switch (id) {
72 case _ADDRESS_LOOPBACK_IP_V4:
73 return new _InternetAddress(
74 InternetAddressType.IP_V4, "127.0.0.1", "localhost", sockaddr);
75 case _ADDRESS_LOOPBACK_IP_V6:
76 return new _InternetAddress(
77 InternetAddressType.IP_V6, "::1", "ip6-localhost", sockaddr);
78 case _ADDRESS_ANY_IP_V4:
79 return new _InternetAddress(
80 InternetAddressType.IP_V4, "0.0.0.0", "0.0.0.0", sockaddr);
81 case _ADDRESS_ANY_IP_V6:
82 return new _InternetAddress(
83 InternetAddressType.IP_V6, "::", "::", sockaddr);
84 default:
85 assert(false);
86 throw new ArgumentError();
87 }
88 }
89
39 String toString() { 90 String toString() {
40 return "InternetAddress('$address', ${type.name})"; 91 return "InternetAddress('$address', ${type.name})";
41 } 92 }
93
94 static Uint8List _fixed(int id) native "InternetAddress_Fixed";
42 } 95 }
43 96
44 97
45 // The _NativeSocket class encapsulates an OS socket. 98 // The _NativeSocket class encapsulates an OS socket.
46 class _NativeSocket extends NativeFieldWrapperClass1 { 99 class _NativeSocket extends NativeFieldWrapperClass1 {
47 // Bit flags used when communicating between the eventhandler and 100 // Bit flags used when communicating between the eventhandler and
48 // dart code. The EVENT flags are used to indicate events of 101 // dart code. The EVENT flags are used to indicate events of
49 // interest when sending a message from dart code to the 102 // interest when sending a message from dart code to the
50 // eventhandler. When receiving a message from the eventhandler the 103 // eventhandler. When receiving a message from the eventhandler the
51 // EVENT flags indicate the events that actually happened. The 104 // EVENT flags indicate the events that actually happened. The
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 // Holds the port of the socket, null if not known. 151 // Holds the port of the socket, null if not known.
99 int localPort; 152 int localPort;
100 153
101 // Holds the address used to connect or bind the socket. 154 // Holds the address used to connect or bind the socket.
102 InternetAddress address; 155 InternetAddress address;
103 156
104 // Native port for socket services. 157 // Native port for socket services.
105 static SendPort socketService; 158 static SendPort socketService;
106 159
107 static Future<List<InternetAddress>> lookup( 160 static Future<List<InternetAddress>> lookup(
108 String host, {InternetAddressType type: InternetAddressType.IPv4}) { 161 String host, {InternetAddressType type: InternetAddressType.IP_V4}) {
109 ensureSocketService(); 162 ensureSocketService();
110 return socketService.call([HOST_NAME_LOOKUP, host, type._value]) 163 return socketService.call([HOST_NAME_LOOKUP, host, type._value])
111 .then((response) { 164 .then((response) {
112 if (isErrorResponse(response)) { 165 if (isErrorResponse(response)) {
113 throw createError(response, "Failed host name lookup"); 166 throw createError(response, "Failed host name lookup");
114 } else { 167 } else {
115 return response.skip(1).map((result) { 168 return response.skip(1).map((result) {
116 var type = new InternetAddressType._from(result[0]); 169 var type = new InternetAddressType._from(result[0]);
117 return new _InternetAddress(type, result[1], host, result[2]); 170 return new _InternetAddress(type, result[1], host, result[2]);
118 }).toList(); 171 }).toList();
(...skipping 916 matching lines...) Expand 10 before | Expand all | Expand 10 after
1035 _raw.onBadCertificate = callback; 1088 _raw.onBadCertificate = callback;
1036 } 1089 }
1037 1090
1038 X509Certificate get peerCertificate { 1091 X509Certificate get peerCertificate {
1039 if (_raw == null) { 1092 if (_raw == null) {
1040 throw new StateError("peerCertificate called on destroyed SecureSocket"); 1093 throw new StateError("peerCertificate called on destroyed SecureSocket");
1041 } 1094 }
1042 return _raw.peerCertificate; 1095 return _raw.peerCertificate;
1043 } 1096 }
1044 } 1097 }
OLDNEW
« no previous file with comments | « runtime/bin/socket.cc ('k') | sdk/lib/_internal/compiler/implementation/lib/io_patch.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698