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 259353003: Make Socket::connect try all addresses given. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 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 | « no previous file | sdk/lib/io/socket.dart » ('j') | sdk/lib/io/socket.dart » ('J')
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 59faecf0918c3ea10c5095c9c5acee4f079f2490..70f078a3aa0a52098c0af03dfc3cd198d340bdcc 100644
--- a/runtime/bin/socket_patch.dart
+++ b/runtime/bin/socket_patch.dart
@@ -481,40 +481,60 @@ class _NativeSocket extends NativeFieldWrapperClass1 {
static Future<_NativeSocket> connect(host, int port) {
return new Future.value(host)
.then((host) {
- if (host is _InternetAddress) return host;
+ if (host is _InternetAddress) return [host];
+ if (host is List) {
Søren Gjesse 2014/04/30 13:11:56 We don't want to support a List here.
Anders Johnsen 2014/05/01 06:31:23 Done.
+ for (var entry in host) {
+ if (entry is! _InternetAddress) {
+ throw new ArgumentError(
+ "When passing a List as `host`, the entries"
+ " must be InternetAddresses");
+ }
+ }
+ return host;
+ }
return lookup(host)
.then((list) {
if (list.length == 0) {
throw createError(response, "Failed host lookup: '$host'");
}
- return list[0];
+ return list;
});
})
- .then((address) {
- var socket = new _NativeSocket.normal();
- socket.address = address;
- var result = socket.nativeCreateConnect(
- address._in_addr, port);
- if (result is OSError) {
- throw createError(result, "Connection failed", address, port);
- } else {
- socket.port; // Query the local port, for error messages.
- var completer = new Completer();
- // Setup handlers for receiving the first write event which
- // indicate that the socket is fully connected.
- socket.setHandlers(
- write: () {
- socket.setListening(read: false, write: false);
- completer.complete(socket);
- },
- error: (e) {
- socket.close();
- completer.completeError(e);
- }
- );
- socket.setListening(read: false, write: true);
- return completer.future;
+ .then((addresses) {
+ assert(addresses is List);
+ var completer = new Completer();
+ var it = addresses.iterator;
+ void run(error) {
+ if (!it.moveNext()) {
+ assert(error != null);
+ completer.completeError(error);
Søren Gjesse 2014/04/30 13:11:56 This will just return the error from the last one
Ivan Posva 2014/04/30 16:28:06 You could collect them all in a List and have a mu
Anders Johnsen 2014/05/01 06:31:23 It's just hard to fit in our current model, withou
+ return;
+ }
+ var address = it.current;
+ var socket = new _NativeSocket.normal();
+ socket.address = address;
+ var result = socket.nativeCreateConnect(address._in_addr, port);
+ if (result is OSError) {
+ run(createError(result, "Connection failed", address, port));
+ } else {
+ socket.port; // Query the local port, for error messages.
+ // Setup handlers for receiving the first write event which
+ // indicate that the socket is fully connected.
+ socket.setHandlers(
+ write: () {
+ socket.setListening(read: false, write: false);
+ completer.complete(socket);
+ },
+ error: (e) {
+ socket.close();
+ run(e);
+ }
+ );
+ socket.setListening(read: false, write: true);
+ }
}
+ run(null);
+ return completer.future;
});
}
« no previous file with comments | « no previous file | sdk/lib/io/socket.dart » ('j') | sdk/lib/io/socket.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698