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

Unified Diff: runtime/bin/socket_patch.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, 8 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 side-by-side diff with in-line comments
Download patch
Index: runtime/bin/socket_patch.dart
diff --git a/runtime/bin/socket_patch.dart b/runtime/bin/socket_patch.dart
index daa59c6448fc629f34fc8e14f99d17e80099c26a..3566fa076f84069c9a060b77b020282fcc19c47c 100644
--- a/runtime/bin/socket_patch.dart
+++ b/runtime/bin/socket_patch.dart
@@ -19,13 +19,43 @@ patch class RawSocket {
patch class InternetAddress {
+ /* patch */ static InternetAddress get LOOPBACK_IP_V4 {
+ return _InternetAddress.LOOPBACK_IP_V4;
+ }
+
+ /* patch */ static InternetAddress get LOOPBACK_IP_V6 {
+ return _InternetAddress.LOOPBACK_IP_V6;
+ }
+
+ /* patch */ static InternetAddress get ANY_IP_V4 {
+ return _InternetAddress.ANY_IP_V4;
+ }
+
+ /* patch */ static InternetAddress get ANY_IP_V6 {
+ return _InternetAddress.ANY_IP_V6;
+ }
+
/* patch */ static Future<List<InternetAddress>> lookup(
- String host, {InternetAddressType type: InternetAddressType.IPv4}) {
+ String host, {InternetAddressType type: InternetAddressType.IP_V4}) {
return _NativeSocket.lookup(host, type: type);
}
}
class _InternetAddress implements InternetAddress {
+ static const int _ADDRESS_LOOPBACK_IP_V4 = 0;
+ static const int _ADDRESS_LOOPBACK_IP_V6 = 1;
+ static const int _ADDRESS_ANY_IP_V4 = 2;
+ static const int _ADDRESS_ANY_IP_V6 = 3;
+
+ static _InternetAddress LOOPBACK_IP_V4 =
+ new _InternetAddress.fixed(_ADDRESS_LOOPBACK_IP_V4);
+ static _InternetAddress LOOPBACK_IP_V6 =
+ new _InternetAddress.fixed(_ADDRESS_LOOPBACK_IP_V6);
+ static _InternetAddress ANY_IP_V4 =
+ new _InternetAddress.fixed(_ADDRESS_ANY_IP_V4);
+ static _InternetAddress ANY_IP_V6 =
+ new _InternetAddress.fixed(_ADDRESS_ANY_IP_V6);
+
final InternetAddressType type;
final String address;
final String host;
@@ -36,9 +66,30 @@ class _InternetAddress implements InternetAddress {
String this.host,
List<int> this._sockaddr_storage);
+ factory _InternetAddress.fixed(int id) {
+ switch (id) {
Bill Hesse 2013/04/30 10:50:22 Maybe put var sockaddr = _fixed(id) before the swi
Søren Gjesse 2013/04/30 11:28:41 Done.
+ case _ADDRESS_LOOPBACK_IP_V4:
+ return new _InternetAddress(
+ InternetAddressType.IP_V4, "127.0.0.1", "localhost", _fixed(id));
+ case _ADDRESS_LOOPBACK_IP_V6:
+ return new _InternetAddress(
+ InternetAddressType.IP_V6, "::1", "ip6-localhost", _fixed(id));
+ case _ADDRESS_ANY_IP_V4:
+ return new _InternetAddress(
+ InternetAddressType.IP_V4, "0.0.0.0", "0.0.0.0", _fixed(id));
+ case _ADDRESS_ANY_IP_V6:
+ return new _InternetAddress(
+ InternetAddressType.IP_V6, "::", "::", _fixed(id));
+ default:
+ assert(false);
Bill Hesse 2013/04/30 10:50:22 There is no return value for the function in the d
Søren Gjesse 2013/04/30 11:28:41 Done.
+ }
+ }
+
String toString() {
return "InternetAddress('$address', ${type.name})";
}
+
+ static Uint8List _fixed(int id) native "InternetAddress_Fixed";
}
@@ -105,7 +156,7 @@ class _NativeSocket extends NativeFieldWrapperClass1 {
static SendPort socketService;
static Future<List<InternetAddress>> lookup(
- String host, {InternetAddressType type: InternetAddressType.IPv4}) {
+ String host, {InternetAddressType type: InternetAddressType.IP_V4}) {
ensureSocketService();
return socketService.call([HOST_NAME_LOOKUP, host, type._value])
.then((response) {

Powered by Google App Engine
This is Rietveld 408576698