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

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

Issue 76383002: Update InternetAddress (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed review commetns Created 7 years, 1 month 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_macos.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) 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, 6 /* patch */ static Future<RawServerSocket> bind(address,
7 int port, 7 int port,
8 {int backlog: 0, 8 {int backlog: 0,
9 bool v6Only: false}) { 9 bool v6Only: false}) {
10 return _RawServerSocket.bind(address, port, backlog, v6Only); 10 return _RawServerSocket.bind(address, port, backlog, v6Only);
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 return _sockaddr_storage[_IPV4_ADDR_OFFSET] == 169 && 99 return _sockaddr_storage[_IPV4_ADDR_OFFSET] == 169 &&
100 _sockaddr_storage[_IPV4_ADDR_OFFSET + 1] == 254; 100 _sockaddr_storage[_IPV4_ADDR_OFFSET + 1] == 254;
101 101
102 case InternetAddressType.IP_V6: 102 case InternetAddressType.IP_V6:
103 // Checking for fe80::/10. 103 // Checking for fe80::/10.
104 return _sockaddr_storage[_IPV6_ADDR_OFFSET] == 0xFE && 104 return _sockaddr_storage[_IPV6_ADDR_OFFSET] == 0xFE &&
105 (_sockaddr_storage[_IPV6_ADDR_OFFSET + 1] & 0xB0) == 0x80; 105 (_sockaddr_storage[_IPV6_ADDR_OFFSET + 1] & 0xB0) == 0x80;
106 } 106 }
107 } 107 }
108 108
109 bool get isMulticast {
110 switch (type) {
111 case InternetAddressType.IP_V4:
112 // Checking for 224.0.0.0 through 239.255.255.255.
113 return _sockaddr_storage[_IPV4_ADDR_OFFSET] >= 224 &&
114 _sockaddr_storage[_IPV4_ADDR_OFFSET] < 240;
115
116 case InternetAddressType.IP_V6:
117 // Checking for ff00::/8.
118 return _sockaddr_storage[_IPV6_ADDR_OFFSET] == 0xFF;
119 }
120 }
121
109 Future<InternetAddress> reverse() => _NativeSocket.reverseLookup(this); 122 Future<InternetAddress> reverse() => _NativeSocket.reverseLookup(this);
110 123
111 _InternetAddress(InternetAddressType this.type, 124 _InternetAddress(InternetAddressType this.type,
112 String this.address, 125 String this.address,
113 String this._host, 126 String this._host,
114 List<int> this._sockaddr_storage); 127 List<int> this._sockaddr_storage);
115 128
129 factory _InternetAddress.parse(String address) {
130 var type = address.indexOf(':') == -1
131 ? InternetAddressType.IP_V4
132 : InternetAddressType.IP_V6;
133 var raw = _parse(type._value, address);
134 if (raw == null) {
135 throw new ArgumentError("Invalid internet address $address");
136 }
137 return new _InternetAddress(type, address, null, raw);
138 }
139
116 factory _InternetAddress.fixed(int id) { 140 factory _InternetAddress.fixed(int id) {
117 var sockaddr = _fixed(id); 141 var sockaddr = _fixed(id);
118 switch (id) { 142 switch (id) {
119 case _ADDRESS_LOOPBACK_IP_V4: 143 case _ADDRESS_LOOPBACK_IP_V4:
120 return new _InternetAddress( 144 return new _InternetAddress(
121 InternetAddressType.IP_V4, "127.0.0.1", null, sockaddr); 145 InternetAddressType.IP_V4, "127.0.0.1", null, sockaddr);
122 case _ADDRESS_LOOPBACK_IP_V6: 146 case _ADDRESS_LOOPBACK_IP_V6:
123 return new _InternetAddress( 147 return new _InternetAddress(
124 InternetAddressType.IP_V6, "::1", null, sockaddr); 148 InternetAddressType.IP_V6, "::1", null, sockaddr);
125 case _ADDRESS_ANY_IP_V4: 149 case _ADDRESS_ANY_IP_V4:
126 return new _InternetAddress( 150 return new _InternetAddress(
127 InternetAddressType.IP_V4, "0.0.0.0", "0.0.0.0", sockaddr); 151 InternetAddressType.IP_V4, "0.0.0.0", "0.0.0.0", sockaddr);
128 case _ADDRESS_ANY_IP_V6: 152 case _ADDRESS_ANY_IP_V6:
129 return new _InternetAddress( 153 return new _InternetAddress(
130 InternetAddressType.IP_V6, "::", "::", sockaddr); 154 InternetAddressType.IP_V6, "::", "::", sockaddr);
131 default: 155 default:
132 assert(false); 156 assert(false);
133 throw new ArgumentError(); 157 throw new ArgumentError();
134 } 158 }
135 } 159 }
136 160
137 // Create a clone of this _InternetAddress replacing the host. 161 // Create a clone of this _InternetAddress replacing the host.
138 _InternetAddress _cloneWithNewHost(String host) { 162 _InternetAddress _cloneWithNewHost(String host) {
139 return new _InternetAddress( 163 return new _InternetAddress(
140 type, address, host, new Uint8List.fromList(_sockaddr_storage)); 164 type, address, host, new Uint8List.fromList(_sockaddr_storage));
141 } 165 }
142 166
167 bool operator ==(other) {
168 if (!(other is _InternetAddress)) return false;
169 if (other.type != type) return false;
170 bool equals = true;
171 for (int i = 0; i < _sockaddr_storage.length && equals; i++) {
172 equals = other._sockaddr_storage[i] == _sockaddr_storage[i];
173 }
174 return equals;
175 }
176
177 int get hashCode {
178 int result = 1;
179 for (int i = 0; i < _sockaddr_storage.length; i++) {
180 result = (result * 31 + _sockaddr_storage[i]) & 0x3FFFFFFF;
181 }
182 return result;
183 }
184
143 String toString() { 185 String toString() {
144 return "InternetAddress('$address', ${type.name})"; 186 return "InternetAddress('$address', ${type.name})";
145 } 187 }
146 188
147 static Uint8List _fixed(int id) native "InternetAddress_Fixed"; 189 static Uint8List _fixed(int id) native "InternetAddress_Fixed";
190 static Uint8List _parse(int type, String address)
191 native "InternetAddress_Parse";
148 } 192 }
149 193
150 class _NetworkInterface implements NetworkInterface { 194 class _NetworkInterface implements NetworkInterface {
151 final String name; 195 final String name;
152 final List<InternetAddress> addresses; 196 final List<InternetAddress> addresses;
153 197
154 _NetworkInterface(String this.name, List<InternetAddress> this.addresses); 198 _NetworkInterface(String this.name, List<InternetAddress> this.addresses);
155 199
156 String toString() { 200 String toString() {
157 return "NetworkInterface('$name', $addresses)"; 201 return "NetworkInterface('$name', $addresses)";
(...skipping 1062 matching lines...) Expand 10 before | Expand all | Expand 10 after
1220 if (_detachReady != null) { 1264 if (_detachReady != null) {
1221 _detachReady.complete(null); 1265 _detachReady.complete(null);
1222 } else { 1266 } else {
1223 if (_raw != null) { 1267 if (_raw != null) {
1224 _raw.shutdown(SocketDirection.SEND); 1268 _raw.shutdown(SocketDirection.SEND);
1225 _disableWriteEvent(); 1269 _disableWriteEvent();
1226 } 1270 }
1227 } 1271 }
1228 } 1272 }
1229 } 1273 }
OLDNEW
« no previous file with comments | « runtime/bin/socket_macos.cc ('k') | runtime/bin/socket_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698