Index: sdk/lib/io/socket.dart |
diff --git a/sdk/lib/io/socket.dart b/sdk/lib/io/socket.dart |
index c5eb054109a2b59d1b5934847f4952608748e944..88cbd08f7f16416a415f2877ea89316ea9eec22d 100644 |
--- a/sdk/lib/io/socket.dart |
+++ b/sdk/lib/io/socket.dart |
@@ -4,6 +4,37 @@ |
part of dart.io; |
+ |
+class InternetAddressType { |
+ static const InternetAddressType IPv4 = const InternetAddressType._(0); |
+ static const InternetAddressType IPv6 = const InternetAddressType._(1); |
+ |
+ final int _value; |
+ |
+ const InternetAddressType._(String this._value); |
+ |
+ String get name { |
+ switch (_value) { |
+ case 0: return "IPv4"; |
+ case 1: return "IPv6"; |
+ default: throw new ArgumentError("Invalid InternetAddress"); |
+ } |
+ } |
+ |
+ String toString() => "InternetAddressType($name)"; |
+ |
+ int get hashCode => _value; |
+ |
+ bool operator==(other) => _value == other._value; |
+} |
+ |
+abstract class InternetAddress { |
+ InternetAddressType type; |
+ String get address; |
+ |
+ external static Future<List<InternetAddress>> lookup(String host); |
+} |
+ |
/** |
* The RawServerSocket is a server socket, providing a stream of low-level |
* [RawSocket]s. |
@@ -144,8 +175,12 @@ abstract class RawSocket implements Stream<RawSocketEvent> { |
* Creates a new socket connection to the host and port and returns a [Future] |
* that will complete with either a [RawSocket] once connected or an error |
* if the host-lookup or connection failed. |
+ * |
+ * [host] can either be a [String] or an [InternetAddress]. If [host] is a |
+ * [String], [connect] will perform a [InternetAddress.lookup] and use |
+ * the first value in the list. |
*/ |
- external static Future<RawSocket> connect(String host, int port); |
+ external static Future<RawSocket> connect(host, int port); |
/** |
* Returns the number of received and non-read bytes in the socket that |
@@ -233,8 +268,12 @@ abstract class Socket implements Stream<List<int>>, IOSink { |
* Creats a new socket connection to the host and port and returns a [Future] |
* that will complete with either a [Socket] once connected or an error |
* if the host-lookup or connection failed. |
+ * |
+ * [host] can either be a [String] or an [InternetAddress]. If [host] is a |
+ * [String], [connect] will perform a [InternetAddress.lookup] and use |
+ * the first value in the list. |
*/ |
- external static Future<Socket> connect(String host, int port); |
+ external static Future<Socket> connect(host, int port); |
/** |
* Destroy the socket in both directions. Calling [destroy] will make the |