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

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: Addressed review comments 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
« no previous file with comments | « runtime/bin/socket.cc ('k') | sdk/lib/_internal/compiler/implementation/lib/io_patch.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/socket_patch.dart
diff --git a/runtime/bin/socket_patch.dart b/runtime/bin/socket_patch.dart
index daa59c6448fc629f34fc8e14f99d17e80099c26a..1515403a76c5972eb6a0c07e7f6b3fcc943739a9 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,32 @@ class _InternetAddress implements InternetAddress {
String this.host,
List<int> this._sockaddr_storage);
+ factory _InternetAddress.fixed(int id) {
+ var sockaddr = _fixed(id);
+ switch (id) {
+ case _ADDRESS_LOOPBACK_IP_V4:
+ return new _InternetAddress(
+ InternetAddressType.IP_V4, "127.0.0.1", "localhost", sockaddr);
+ case _ADDRESS_LOOPBACK_IP_V6:
+ return new _InternetAddress(
+ InternetAddressType.IP_V6, "::1", "ip6-localhost", sockaddr);
+ case _ADDRESS_ANY_IP_V4:
+ return new _InternetAddress(
+ InternetAddressType.IP_V4, "0.0.0.0", "0.0.0.0", sockaddr);
+ case _ADDRESS_ANY_IP_V6:
+ return new _InternetAddress(
+ InternetAddressType.IP_V6, "::", "::", sockaddr);
+ default:
+ assert(false);
+ throw new ArgumentError();
+ }
+ }
+
String toString() {
return "InternetAddress('$address', ${type.name})";
}
+
+ static Uint8List _fixed(int id) native "InternetAddress_Fixed";
}
@@ -105,7 +158,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) {
« no previous file with comments | « runtime/bin/socket.cc ('k') | sdk/lib/_internal/compiler/implementation/lib/io_patch.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698