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

Unified Diff: runtime/bin/socket_patch.dart

Issue 16514010: Add NetworkAdaptor to dart:io. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Add test file. Created 7 years, 6 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 d603532e84c93176f182ca76489ac8781fb24877..e0dd3412f273180ebb07766b200e3028b00d8724 100644
--- a/runtime/bin/socket_patch.dart
+++ b/runtime/bin/socket_patch.dart
@@ -42,6 +42,15 @@ patch class InternetAddress {
}
}
+patch class NetworkAdaptor {
+ /* patch */ static Future<List<NetworkAdaptor>> list({
+ bool includeLoopback: false,
+ InternetAddressType type: InternetAddressType.ANY}) {
+ return _NativeSocket.listAdaptors(includeLoopback: includeLoopback,
+ type: type);
+ }
+}
+
class _InternetAddress implements InternetAddress {
static const int _ADDRESS_LOOPBACK_IP_V4 = 0;
static const int _ADDRESS_LOOPBACK_IP_V6 = 1;
@@ -95,6 +104,17 @@ class _InternetAddress implements InternetAddress {
static Uint8List _fixed(int id) native "InternetAddress_Fixed";
}
+class _NetworkAdaptor implements NetworkAdaptor {
+ final String name;
+ final List<InternetAddress> addresses;
+
+ _NetworkAdaptor(String this.name, List<InternetAddress> this.addresses);
+
+ String toString() {
+ return "NetworkAdaptor('$name', $addresses)";
+ }
+}
+
// The _NativeSocket class encapsulates an OS socket.
class _NativeSocket extends NativeFieldWrapperClass1 {
@@ -131,6 +151,7 @@ class _NativeSocket extends NativeFieldWrapperClass1 {
// Native port messages.
static const HOST_NAME_LOOKUP = 0;
+ static const LIST_ADAPTORS = 1;
// Socket close state
bool isClosed = false;
@@ -174,6 +195,33 @@ class _NativeSocket extends NativeFieldWrapperClass1 {
});
}
+ static Future<List<NetworkAdaptor>> listAdaptors({
+ bool includeLoopback: false,
+ InternetAddressType type: InternetAddressType.ANY}) {
+ ensureSocketService();
+ return socketService.call([LIST_ADAPTORS, includeLoopback, type._value])
+ .then((response) {
+ if (isErrorResponse(response)) {
+ throw createError(response, "Failed listing adaptors");
+ } else {
+ var list = new List<NetworkAdaptor>();
+ var map = response.skip(1)
+ .fold(new Map<String, NetworkAdaptor>(), (map, result) {
+ var type = new InternetAddressType._from(result[0]);
+ var name = result[3];
+ map.putIfAbsent(name, () => new List<InternetAddress>());
+ map[name].add(
+ new _InternetAddress(type, result[1], "", result[2]));
+ return map;
+ })
+ .forEach((name, addresses) {
+ list.add(new _NetworkAdaptor(name, addresses));
+ });
+ return list;
+ }
+ });
+ }
+
static Future<_NativeSocket> connect(host, int port) {
return new Future.value(host)
.then((host) {

Powered by Google App Engine
This is Rietveld 408576698