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

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: Fixes 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 and IP version 6 are supported.
Bill Hesse 2013/04/30 10:50:22 Maybe say (IPv4) and (IPv6) in parentheses? I hav
Søren Gjesse 2013/04/30 11:28:41 Done.
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 local
45 * address, for wich a socket can be connected to or bound on. 45 * address, for wich a socket can be connected to or bound on.
Bill Hesse 2013/04/30 10:50:22 to which a socket can be connected or a listening
Søren Gjesse 2013/04/30 11:28:41 Done.
46 * 46 *
47 */ 47 */
48 abstract class InternetAddress { 48 abstract class InternetAddress {
49 /** 49 /**
50 * The [type] of the [InternetAddress] specified what IP procotol. 50 * IP version 4 loopback address. Use this address when listening on
51 * or connecting to the loopback adapter using IP version 4.
52 */
53 external static InternetAddress get LOOPBACK_IP_V4;
54
55 /**
56 * IP version 6 loopback address. Use this address when listening on
57 * or connecting to the loopback adapter using IP version 6.
58 */
59 external static InternetAddress get LOOPBACK_IP_V6;
60
61 /**
62 * IP version 4 any address. Use this address when listening on
63 * all adapters IP addresses using IP version 4.
64 */
65 external static InternetAddress get ANY_IP_V4;
66
67 /**
68 * IP version 6 any address. Use this address when listening on
69 * all adapters IP addresses using IP version 6.
70 */
71 external static InternetAddress get ANY_IP_V6;
72
73 /**
74 * The [type] of the [InternetAddress] specified what IP protocol.
51 */ 75 */
52 InternetAddressType type; 76 InternetAddressType type;
53 77
54 /** 78 /**
55 * The resolved address of the host. 79 * The resolved address of the host.
56 */ 80 */
57 String get address; 81 String get address;
58 82
59 /** 83 /**
60 * The host used to lookup the address. 84 * The host used to lookup the address.
61 */ 85 */
62 String get host; 86 String get host;
63 87
64 /** 88 /**
65 * Lookup a host, returning a Future of a list of [InternetAddress]s. If 89 * Lookup a host, returning a Future of a list of
66 * [type] is [InternetAddressType.ANY], it will lookup both IPv4 and IPv6 90 * [InternetAddress]s. If [type] is [InternetAddressType.ANY], it
67 * addresses. The order of the list depends on the local machine and the DNS 91 * will lookup both IP version 4 and IP version 6 addresses. The
68 * lookup performed, and can as such change over time. 92 * order of the list depends on the local machine and the DNS lookup
93 * performed, and can as such change over time.
Bill Hesse 2013/04/30 10:50:22 I would remove "as such". If necessary, say "ther
Søren Gjesse 2013/04/30 11:28:41 Done.
69 */ 94 */
70 external static Future<List<InternetAddress>> lookup( 95 external static Future<List<InternetAddress>> lookup(
71 String host, {InternetAddressType type: InternetAddressType.IPv4}); 96 String host, {InternetAddressType type: InternetAddressType.IP_V4});
72 } 97 }
73 98
74 /** 99 /**
75 * The RawServerSocket is a server socket, providing a stream of low-level 100 * The RawServerSocket is a server socket, providing a stream of low-level
76 * [RawSocket]s. 101 * [RawSocket]s.
77 * 102 *
78 * See [RawSocket] for more info. 103 * See [RawSocket] for more info.
79 */ 104 */
80 abstract class RawServerSocket implements Stream<RawSocket> { 105 abstract class RawServerSocket implements Stream<RawSocket> {
81 /** 106 /**
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 sb.write(" ($osError)"); 393 sb.write(" ($osError)");
369 } 394 }
370 } else if (osError != null) { 395 } else if (osError != null) {
371 sb.write(": $osError"); 396 sb.write(": $osError");
372 } 397 }
373 return sb.toString(); 398 return sb.toString();
374 } 399 }
375 final String message; 400 final String message;
376 final OSError osError; 401 final OSError osError;
377 } 402 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698