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

Side by Side Diff: sdk/lib/io/socket.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
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 part of dart.io; 5 part of dart.io;
6 6
7 7
8 /** 8 /**
9 * [InternetAddressType] is the type an [InternetAddress]. Currently, IPv4 and 9 * [InternetAddressType] is the type an [InternetAddress]. Currently,
10 * IPv6 are supported. 10 * IP version 4 (IPv4) and IP version 6 (IPv6) are supported.
11 */ 11 */
12 class InternetAddressType { 12 class InternetAddressType {
13 static const InternetAddressType IPv4 = const InternetAddressType._(0); 13 static const InternetAddressType IP_V4 = const InternetAddressType._(0);
14 static const InternetAddressType IPv6 = const InternetAddressType._(1); 14 static const InternetAddressType IP_V6 = const InternetAddressType._(1);
15 static const InternetAddressType ANY = const InternetAddressType._(-1); 15 static const InternetAddressType ANY = const InternetAddressType._(-1);
16 16
17 final int _value; 17 final int _value;
18 18
19 const InternetAddressType._(int this._value); 19 const InternetAddressType._(int this._value);
20 20
21 factory InternetAddressType._from(int value) { 21 factory InternetAddressType._from(int value) {
22 if (value == 0) return IPv4; 22 if (value == 0) return IP_V4;
23 if (value == 1) return IPv6; 23 if (value == 1) return IP_V6;
24 throw new ArgumentError("Invalid type: $value"); 24 throw new ArgumentError("Invalid type: $value");
25 } 25 }
26 26
27 /** 27 /**
28 * Get the name of the type, e.g. "IPv4" or "IPv6". 28 * Get the name of the type, e.g. "IP_V4" or "IP_V6".
29 */ 29 */
30 String get name { 30 String get name {
31 switch (_value) { 31 switch (_value) {
32 case -1: return "ANY"; 32 case -1: return "ANY";
33 case 0: return "IPv4"; 33 case 0: return "IP_V4";
34 case 1: return "IPv6"; 34 case 1: return "IP_V6";
35 default: throw new ArgumentError("Invalid InternetAddress"); 35 default: throw new ArgumentError("Invalid InternetAddress");
36 } 36 }
37 } 37 }
38 38
39 String toString() => "InternetAddressType($name)"; 39 String toString() => "InternetAddressType: $name";
40 } 40 }
41 41
42 42
43 /** 43 /**
44 * The [InternetAddress] is an object reflecting either a remote or a local 44 * The [InternetAddress] is an object reflecting either a remote or a
45 * address, for wich a socket can be connected to or bound on. 45 * local address. When combined with a port number, this represents a
46 * 46 * endpoint that a socket can connect to or a listening socket can
47 * bind to.
47 */ 48 */
48 abstract class InternetAddress { 49 abstract class InternetAddress {
49 /** 50 /**
50 * The [type] of the [InternetAddress] specified what IP procotol. 51 * IP version 4 loopback address. Use this address when listening on
52 * or connecting to the loopback adapter using IP version 4 (IPv4).
53 */
54 external static InternetAddress get LOOPBACK_IP_V4;
55
56 /**
57 * IP version 6 loopback address. Use this address when listening on
58 * or connecting to the loopback adapter using IP version 6 (IPv6).
59 */
60 external static InternetAddress get LOOPBACK_IP_V6;
61
62 /**
63 * IP version 4 any address. Use this address when listening on
64 * all adapters IP addresses using IP version 4 (IPv4).
65 */
66 external static InternetAddress get ANY_IP_V4;
67
68 /**
69 * IP version 6 any address. Use this address when listening on
70 * all adapters IP addresses using IP version 6 (IPv6).
71 */
72 external static InternetAddress get ANY_IP_V6;
73
74 /**
75 * The [type] of the [InternetAddress] specified what IP protocol.
51 */ 76 */
52 InternetAddressType type; 77 InternetAddressType type;
53 78
54 /** 79 /**
55 * The resolved address of the host. 80 * The resolved address of the host.
56 */ 81 */
57 String get address; 82 String get address;
58 83
59 /** 84 /**
60 * The host used to lookup the address. 85 * The host used to lookup the address.
61 */ 86 */
62 String get host; 87 String get host;
63 88
64 /** 89 /**
65 * Lookup a host, returning a Future of a list of [InternetAddress]s. If 90 * Lookup a host, returning a Future of a list of
66 * [type] is [InternetAddressType.ANY], it will lookup both IPv4 and IPv6 91 * [InternetAddress]s. If [type] is [InternetAddressType.ANY], it
67 * addresses. The order of the list depends on the local machine and the DNS 92 * will lookup both IP version 4 (IPv4) and IP version 6 (IPv6)
68 * lookup performed, and can as such change over time. 93 * addresses. If [type] is either [InternetAddressType.IP_V4] or
94 * [InternetAddressType.IP_V6] it will only lookup addresses of the
95 * specified type. The order of the list can, and most likely will,
96 * change over time.
69 */ 97 */
70 external static Future<List<InternetAddress>> lookup( 98 external static Future<List<InternetAddress>> lookup(
71 String host, {InternetAddressType type: InternetAddressType.IPv4}); 99 String host, {InternetAddressType type: InternetAddressType.IP_V4});
72 } 100 }
73 101
74 /** 102 /**
75 * The RawServerSocket is a server socket, providing a stream of low-level 103 * The RawServerSocket is a server socket, providing a stream of low-level
76 * [RawSocket]s. 104 * [RawSocket]s.
77 * 105 *
78 * See [RawSocket] for more info. 106 * See [RawSocket] for more info.
79 */ 107 */
80 abstract class RawServerSocket implements Stream<RawSocket> { 108 abstract class RawServerSocket implements Stream<RawSocket> {
81 /** 109 /**
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 sb.write(" ($osError)"); 396 sb.write(" ($osError)");
369 } 397 }
370 } else if (osError != null) { 398 } else if (osError != null) {
371 sb.write(": $osError"); 399 sb.write(": $osError");
372 } 400 }
373 return sb.toString(); 401 return sb.toString();
374 } 402 }
375 final String message; 403 final String message;
376 final OSError osError; 404 final OSError osError;
377 } 405 }
OLDNEW
« no previous file with comments | « sdk/lib/_internal/compiler/implementation/lib/io_patch.dart ('k') | tests/standalone/io/internet_address_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698