OLD | NEW |
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 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 return "InternetAddress('$address', ${type.name})"; | 190 return "InternetAddress('$address', ${type.name})"; |
191 } | 191 } |
192 | 192 |
193 static Uint8List _fixed(int id) native "InternetAddress_Fixed"; | 193 static Uint8List _fixed(int id) native "InternetAddress_Fixed"; |
194 static Uint8List _parse(int type, String address) | 194 static Uint8List _parse(int type, String address) |
195 native "InternetAddress_Parse"; | 195 native "InternetAddress_Parse"; |
196 } | 196 } |
197 | 197 |
198 class _NetworkInterface implements NetworkInterface { | 198 class _NetworkInterface implements NetworkInterface { |
199 final String name; | 199 final String name; |
200 final List<InternetAddress> addresses; | 200 final int index; |
| 201 final List<InternetAddress> addresses = []; |
201 | 202 |
202 _NetworkInterface(String this.name, List<InternetAddress> this.addresses); | 203 _NetworkInterface(this.name, this.index); |
203 | 204 |
204 String toString() { | 205 String toString() { |
205 return "NetworkInterface('$name', $addresses)"; | 206 return "NetworkInterface('$name', $addresses)"; |
206 } | 207 } |
207 } | 208 } |
208 | 209 |
209 | 210 |
210 // The _NativeSocket class encapsulates an OS socket. | 211 // The _NativeSocket class encapsulates an OS socket. |
211 class _NativeSocket extends NativeFieldWrapperClass1 { | 212 class _NativeSocket extends NativeFieldWrapperClass1 { |
212 // Bit flags used when communicating between the eventhandler and | 213 // Bit flags used when communicating between the eventhandler and |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 | 299 |
299 static Future<List<NetworkInterface>> listInterfaces({ | 300 static Future<List<NetworkInterface>> listInterfaces({ |
300 bool includeLoopback: false, | 301 bool includeLoopback: false, |
301 bool includeLinkLocal: false, | 302 bool includeLinkLocal: false, |
302 InternetAddressType type: InternetAddressType.ANY}) { | 303 InternetAddressType type: InternetAddressType.ANY}) { |
303 return _IOService.dispatch(_SOCKET_LIST_INTERFACES, [type._value]) | 304 return _IOService.dispatch(_SOCKET_LIST_INTERFACES, [type._value]) |
304 .then((response) { | 305 .then((response) { |
305 if (isErrorResponse(response)) { | 306 if (isErrorResponse(response)) { |
306 throw createError(response, "Failed listing interfaces"); | 307 throw createError(response, "Failed listing interfaces"); |
307 } else { | 308 } else { |
308 var list = new List<NetworkInterface>(); | |
309 var map = response.skip(1) | 309 var map = response.skip(1) |
310 .fold(new Map<String, List<InternetAddress>>(), (map, result) { | 310 .fold(new Map<String, List<InternetAddress>>(), (map, result) { |
311 var type = new InternetAddressType._from(result[0]); | 311 var type = new InternetAddressType._from(result[0]); |
312 var name = result[3]; | 312 var name = result[3]; |
| 313 var index = result[4]; |
313 var address = new _InternetAddress( | 314 var address = new _InternetAddress( |
314 type, result[1], "", result[2]); | 315 type, result[1], "", result[2]); |
315 if (!includeLinkLocal && address.isLinkLocal) return map; | 316 if (!includeLinkLocal && address.isLinkLocal) return map; |
316 if (!includeLoopback && address.isLoopback) return map; | 317 if (!includeLoopback && address.isLoopback) return map; |
317 map.putIfAbsent(name, () => new List<InternetAddress>()); | 318 map.putIfAbsent( |
318 map[name].add(address); | 319 name, () => new _NetworkInterface(name, index)); |
| 320 map[name].addresses.add(address); |
319 return map; | 321 return map; |
320 }) | |
321 .forEach((name, addresses) { | |
322 list.add(new _NetworkInterface(name, addresses)); | |
323 }); | 322 }); |
324 return list; | 323 return map.values.toList(); |
325 } | 324 } |
326 }); | 325 }); |
327 } | 326 } |
328 | 327 |
329 static Future<_NativeSocket> connect(host, int port) { | 328 static Future<_NativeSocket> connect(host, int port) { |
330 return new Future.value(host) | 329 return new Future.value(host) |
331 .then((host) { | 330 .then((host) { |
332 if (host is _InternetAddress) return host; | 331 if (host is _InternetAddress) return host; |
333 return lookup(host) | 332 return lookup(host) |
334 .then((list) { | 333 .then((list) { |
(...skipping 937 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1272 if (_detachReady != null) { | 1271 if (_detachReady != null) { |
1273 _detachReady.complete(null); | 1272 _detachReady.complete(null); |
1274 } else { | 1273 } else { |
1275 if (_raw != null) { | 1274 if (_raw != null) { |
1276 _raw.shutdown(SocketDirection.SEND); | 1275 _raw.shutdown(SocketDirection.SEND); |
1277 _disableWriteEvent(); | 1276 _disableWriteEvent(); |
1278 } | 1277 } |
1279 } | 1278 } |
1280 } | 1279 } |
1281 } | 1280 } |
OLD | NEW |